0
0
Spring Bootframework~20 mins

@PutMapping and @DeleteMapping in Spring Boot - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Spring Boot REST Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2: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
    }
AHTTP 200 OK with empty body
BHTTP 204 No Content
CHTTP 201 Created
DHTTP 404 Not Found
Attempts:
2 left
💡 Hint
Think about what HTTP status means no content is returned.
📝 Syntax
intermediate
2: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();
    }
ARemove the return statement
BChange @DeleteMapping to @GetMapping
CAdd a semicolon after userService.delete(id);
DChange @PathVariable Long id to @RequestParam Long id
Attempts:
2 left
💡 Hint
Look for missing punctuation in Java statements.
state_output
advanced
2: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);
    }
AThe updated Product object serialized as JSON
BAn empty response body with HTTP 204 status
CA plain text message 'Product updated successfully'
DHTTP 404 error if product not found
Attempts:
2 left
💡 Hint
Look at what is returned inside ResponseEntity.ok()
🔧 Debug
advanced
2: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);
    }
AThe orderService.findById method throws an exception
BThere is no @DeleteMapping method for /orders/{id}, only @GetMapping exists
CThe client request method is incorrect and should be GET
DThe @GetMapping method is missing @DeleteMapping annotation
Attempts:
2 left
💡 Hint
Check which HTTP methods the controller supports for the URL.
🧠 Conceptual
expert
3:00remaining
Which statement about @PutMapping and @DeleteMapping is true?
Select the correct statement about the behavior of @PutMapping and @DeleteMapping in Spring Boot controllers.
A@PutMapping and @DeleteMapping cannot be used together in the same controller class.
B@PutMapping always creates new resources; @DeleteMapping returns the deleted resource in the response body.
C@PutMapping and @DeleteMapping require the HTTP request body to be empty.
D@PutMapping is idempotent and typically used to update resources; @DeleteMapping is idempotent and used to remove resources.
Attempts:
2 left
💡 Hint
Think about HTTP method semantics and REST principles.