Recall & Review
beginner
What is
ResponseEntity in Spring Boot?<p><code>ResponseEntity</code> is a class that represents the whole HTTP response. It lets you control the status code, headers, and body of the response.</p>Click to reveal answer
beginner
How do you set a custom HTTP status code using
ResponseEntity?You can set a custom status by using ResponseEntity.status(HttpStatus.YOUR_STATUS) and then build the response.
Click to reveal answer
intermediate
How can you add HTTP headers using
ResponseEntity?Use the headers(HttpHeaders headers) method or header(String name, String value) when building the ResponseEntity.
Click to reveal answer
beginner
What is the advantage of using
ResponseEntity over returning just an object in a controller?ResponseEntity gives you full control over the HTTP response, including status codes and headers, not just the body.
Click to reveal answer
beginner
Show a simple example of returning a 404 Not Found status with
ResponseEntity.return ResponseEntity.status(HttpStatus.NOT_FOUND).body("Resource not found");Click to reveal answer
What does
ResponseEntity allow you to control in a Spring Boot response?✗ Incorrect
ResponseEntity controls the full HTTP response: status code, headers, and body.
How do you create a
ResponseEntity with a 201 Created status?✗ Incorrect
Use ResponseEntity.status(HttpStatus.CREATED) to set 201 Created status.
Which method adds a header to a
ResponseEntity?✗ Incorrect
The header method adds HTTP headers to the response.
What is the default HTTP status if you return an object directly from a controller without
ResponseEntity?✗ Incorrect
Returning an object directly defaults to 200 OK status.
Which of these is a valid way to return a 404 response with a message using
ResponseEntity?✗ Incorrect
Use status(HttpStatus.NOT_FOUND) with body to return 404 with message.
Explain how
ResponseEntity helps you control the HTTP response in Spring Boot.Think about what parts of the HTTP response you can customize.
You got /4 concepts.
Describe how to build a
ResponseEntity that returns a 201 Created status with a custom header and a JSON body.Remember the builder pattern methods on ResponseEntity.
You got /3 concepts.