Challenge - 5 Problems
Spring Boot REST Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What happens when a @PutMapping method returns void?
Consider a Spring Boot REST controller method annotated with @PutMapping that returns void. What is the HTTP response status code by default when this method completes successfully?
Spring Boot
@PutMapping("/items/{id}")
public void updateItem(@PathVariable String id, @RequestBody Item item) {
// update logic
}Attempts:
2 left
💡 Hint
Think about what HTTP status means no content is returned.
✗ Incorrect
When a @PutMapping method returns void, Spring Boot by default sends HTTP 200 OK with an empty body, indicating the request was successful but no content is returned.
📝 Syntax
intermediate2:00remaining
Identify the syntax error in this @DeleteMapping method
Which option correctly fixes the syntax error in this @DeleteMapping method?
Spring Boot
@DeleteMapping("/users/{id}") public ResponseEntity deleteUser(@PathVariable Long id) { userService.delete(id); return ResponseEntity.ok().build(); }
Attempts:
2 left
💡 Hint
Look for missing punctuation in Java statements.
✗ Incorrect
The method call userService.delete(id) is missing a semicolon at the end, causing a syntax error.
❓ state_output
advanced2:00remaining
What is the response body of this @PutMapping method?
Given the following @PutMapping method, what will be the HTTP response body when updating an item successfully?
Spring Boot
@PutMapping("/products/{id}") public ResponseEntity<Product> updateProduct(@PathVariable Long id, @RequestBody Product product) { Product updated = productService.update(id, product); return ResponseEntity.ok(updated); }
Attempts:
2 left
💡 Hint
Look at what is returned inside ResponseEntity.ok()
✗ Incorrect
The method returns ResponseEntity.ok(updated), so the updated Product object is serialized to JSON and sent in the response body with HTTP 200 status.
🔧 Debug
advanced2:00remaining
Why does this @DeleteMapping method cause a 405 Method Not Allowed error?
A client sends a DELETE request to /orders/123 but receives a 405 Method Not Allowed error. Which option explains the most likely cause?
Spring Boot
@GetMapping("/orders/{id}") public Order getOrder(@PathVariable Long id) { return orderService.findById(id); }
Attempts:
2 left
💡 Hint
Check which HTTP methods the controller supports for the URL.
✗ Incorrect
The controller only has a @GetMapping for /orders/{id}, so DELETE requests to that URL are not handled, causing 405 error.
🧠 Conceptual
expert3:00remaining
Which statement about @PutMapping and @DeleteMapping is true?
Select the correct statement about the behavior of @PutMapping and @DeleteMapping in Spring Boot controllers.
Attempts:
2 left
💡 Hint
Think about HTTP method semantics and REST principles.
✗ Incorrect
@PutMapping corresponds to HTTP PUT which is idempotent and used for updating resources. @DeleteMapping corresponds to HTTP DELETE which is also idempotent and used to delete resources.