Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a method that handles HTTP PUT requests.
Spring Boot
@[1]("/update") public ResponseEntity<String> updateItem() { return ResponseEntity.ok("Item updated"); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using @GetMapping instead of @PutMapping
Using @PostMapping for updates
Confusing @DeleteMapping with @PutMapping
✗ Incorrect
The @PutMapping annotation is used to handle HTTP PUT requests, which are typically used to update resources.
2fill in blank
mediumComplete the code to create a method that handles HTTP DELETE requests.
Spring Boot
@[1]("/delete/{id}") public ResponseEntity<String> deleteItem(@PathVariable Long id) { return ResponseEntity.ok("Item deleted"); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using @PutMapping instead of @DeleteMapping
Using @GetMapping for deletions
Missing @PathVariable annotation
✗ Incorrect
The @DeleteMapping annotation is used to handle HTTP DELETE requests, which are used to delete resources.
3fill in blank
hardFix the error in the method annotation to correctly handle HTTP PUT requests.
Spring Boot
@[1]("/modify") public ResponseEntity<String> modifyItem() { return ResponseEntity.ok("Item modified"); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using @DeleteMapping for PUT requests
Using @PostMapping instead of PUT
Missing method attribute in @RequestMapping
✗ Incorrect
Using @RequestMapping with method = RequestMethod.PUT is a valid way to handle PUT requests, especially if you want to specify the HTTP method explicitly.
4fill in blank
hardFill both blanks to create a method that handles HTTP DELETE requests and extracts the path variable.
Spring Boot
@[1]("/remove/{id}") public ResponseEntity<String> removeItem(@[2] Long id) { return ResponseEntity.ok("Removed item " + id); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using @RequestParam instead of @PathVariable
Using @PutMapping instead of @DeleteMapping
Forgetting to annotate the method parameter
✗ Incorrect
The method uses @DeleteMapping to handle DELETE requests and @PathVariable to extract the 'id' from the URL path.
5fill in blank
hardFill all three blanks to create a method that handles HTTP PUT requests, extracts a path variable, and consumes JSON data.
Spring Boot
@[1](value = "/edit/{id}", consumes = "application/json") public ResponseEntity<String> editItem(@[2] Long id, @[3] Item item) { return ResponseEntity.ok("Edited item " + id); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using @DeleteMapping instead of @PutMapping
Using @RequestParam instead of @PathVariable
Forgetting @RequestBody for JSON input
✗ Incorrect
The method uses @PutMapping to handle PUT requests, @PathVariable to get the 'id' from the URL, and @RequestBody to get the JSON data from the request body.