Recall & Review
beginner
How do you return a 200 OK status with a response body in Spring Boot?
Use
ResponseEntity.ok(body) to return a 200 OK status with the given response body.Click to reveal answer
beginner
What class in Spring Boot helps you customize HTTP status codes in responses?The <code>ResponseEntity</code> class allows you to set the HTTP status code, headers, and body in your response.Click to reveal answer
beginner
How can you return a 404 Not Found status when a resource is missing?
Return
ResponseEntity.notFound().build() to send a 404 Not Found status without a body.Click to reveal answer
intermediate
What annotation can you use to set the HTTP status code directly on a controller method?
Use <code>@ResponseStatus(HttpStatus.CODE)</code> on a method or exception class to set the HTTP status code.Click to reveal answer
intermediate
How do you return a 201 Created status with a location header in Spring Boot?
Use
ResponseEntity.created(URI).body(body) to return 201 Created with a Location header pointing to the new resource.Click to reveal answer
Which Spring Boot class lets you set HTTP status codes in responses?
✗ Incorrect
ResponseEntity is used to customize HTTP status codes, headers, and body in Spring Boot responses.
How do you return a 404 Not Found status without a body?
✗ Incorrect
ResponseEntity.notFound().build() returns a 404 status with no body.
Which annotation sets a fixed HTTP status code on a controller method?
✗ Incorrect
@ResponseStatus sets the HTTP status code for the method or exception.
What status code is typically returned when a new resource is created?
✗ Incorrect
201 Created indicates a new resource was successfully created.
How do you include a Location header pointing to a new resource in the response?
✗ Incorrect
ResponseEntity.created(URI).body(body) sets the Location header and returns 201 Created.
Explain how to return different HTTP status codes from a Spring Boot controller method.
Think about ResponseEntity methods and the @ResponseStatus annotation.
You got /5 concepts.
Describe how to return a 201 Created status with a Location header in Spring Boot.
Focus on ResponseEntity.created and URI usage.
You got /4 concepts.