Recall & Review
beginner
What is the purpose of the @PutMapping annotation in Spring Boot?
The @PutMapping annotation maps HTTP PUT requests to a specific method in a controller. It is used to update existing resources on the server.
Click to reveal answer
beginner
What does the @DeleteMapping annotation do in a Spring Boot controller?
The @DeleteMapping annotation maps HTTP DELETE requests to a method. It is used to delete resources from the server.
Click to reveal answer
intermediate
How do @PutMapping and @DeleteMapping differ from @GetMapping and @PostMapping?
@PutMapping and @DeleteMapping handle updating and deleting resources, respectively, while @GetMapping retrieves data and @PostMapping creates new resources.
Click to reveal answer
intermediate
Show a simple example of a method using @PutMapping to update a user by ID.
Example:
@PutMapping("/users/{id}")
public ResponseEntity<User> updateUser(@PathVariable Long id, @RequestBody User user) {
// update logic here
User updatedUser = userService.updateUser(id, user);
return ResponseEntity.ok(updatedUser);
}Click to reveal answer
intermediate
Why is it important to use @DeleteMapping for delete operations instead of @GetMapping?
Using @DeleteMapping clearly signals the intent to delete a resource and follows HTTP standards. @GetMapping is meant for safe, read-only operations and should not change server state.
Click to reveal answer
Which HTTP method does @PutMapping handle?
✗ Incorrect
@PutMapping maps HTTP PUT requests, which are used to update resources.
What is the main use of @DeleteMapping in Spring Boot?
✗ Incorrect
@DeleteMapping is used to handle HTTP DELETE requests to remove resources.
Which annotation would you use to update a resource at the URL '/items/{id}'?
✗ Incorrect
@PutMapping is the correct annotation for updating resources at a specific URL.
Which HTTP method should NOT be used to delete a resource?
✗ Incorrect
GET requests are meant for reading data and should not change server state like deleting resources.
In a Spring Boot controller, which annotation is best for a method that removes a user by ID?
✗ Incorrect
@DeleteMapping is designed for delete operations, making it the best choice.
Explain how @PutMapping and @DeleteMapping are used in a Spring Boot REST controller.
Think about how HTTP methods relate to resource actions.
You got /4 concepts.
Describe why it is important to use the correct HTTP method annotations like @PutMapping and @DeleteMapping in REST APIs.
Consider how clients and servers understand requests.
You got /4 concepts.