ResponseEntity — Concept Check
Questions on ResponseEntity. Wraps the response body, HTTP status code, and headers in a single return type, giving full control over every aspect of the HTTP response.
Questions in this quiz
8 questions on ResponseEntity — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.An API endpoint needs to return a 201 Created status with a Location header after creating a resource. Which ResponseEntity method should be used?
- AResponseEntity.created(uri)
- BResponseEntity.notFound()
- CResponseEntity.noContent()
- DResponseEntity.ok()
2.A DELETE request to an endpoint should return a status indicating the resource was successfully deleted without a response body. Which ResponseEntity method is appropriate?
- AResponseEntity.created(uri)
- BResponseEntity.noContent()
- CResponseEntity.notFound()
- DResponseEntity.ok()
3.A developer wants to return a 404 Not Found status when a requested resource is absent. Which ResponseEntity method should they use?
- AResponseEntity.noContent()
- BResponseEntity.ok()
- CResponseEntity.created(uri)
- DResponseEntity.notFound()
4.An order service needs to add caching headers to its response. Which method allows adding headers like ETag and Cache-Control?
- AResponseEntity.notFound()
- BResponseEntity.noContent()
- CResponseEntity.ok().header(name, value)
- DResponseEntity.created(uri)
5.A developer mistakenly uses ResponseEntity.ok() to return a 201 status after creating a resource. What is the actual status returned?
- A204 No Content
- B201 Created
- C200 OK
- D404 Not Found
6.A controller method returns ResponseEntity.notFound().build() when a resource is absent. What status code is returned?
- A201 Created
- B200 OK
- C404 Not Found
- D204 No Content
7.What is the purpose of using ResponseEntity in a Spring controller?
- ATo manage database transactions
- BTo handle exceptions globally
- CTo wrap response body, status code, and headers
- DTo only return the response body
8.A developer uses ResponseEntity.created(uri).body(created) after creating a resource. What headers and status are included in the response?
- AETag header and 200 OK status
- BLocation header and 201 Created status
- CNo headers and 404 Not Found status
- DCache-Control header and 204 No Content status