Request & Response — Concept Check
Questions on Request & Response. @RequestBody deserializes the HTTP request body into a Java object; ResponseEntity gives you full control over status, headers, and body. These two are the backbone of every REST interaction.
Questions in this quiz
8 questions on Request & Response — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.A client sends a JSON request to create an order, but the server responds with a 400 error. What is the most likely reason?
- AThe client used an unsupported HTTP method.
- BThe server is down.
- CThe endpoint URL is incorrect.
- DThe JSON structure does not match the Java record.
2.When should you use ResponseEntity over a simple return type in a Spring controller?
- AWhen you want to log the response data.
- BWhen you need to handle file uploads.
- CWhen you want to return XML instead of JSON.
- DWhen you need to set custom HTTP headers or status codes.
3.A developer uses @RequestBody but forgets to include @Valid. What might happen?
- AThe request will be ignored by the controller.
- BValidation constraints on the request body won't be enforced.
- CThe request body will not be deserialized into a Java object.
- DThe server will return a 500 error.
4.You receive a 201 Created response with a Location header. What does this indicate?
- AThe request was processed but no resource was created.
- BThe server is redirecting the request to another endpoint.
- CThe client must authenticate before accessing the resource.
- DA new resource was successfully created.
5.A client receives a 304 Not Modified response. What should the client do next?
- AAssume the resource does not exist.
- BRetry the request with a different HTTP method.
- CUse the cached version of the resource.
- DSend a new request without the If-None-Match header.
6.What happens if a JSON request body violates Bean Validation constraints in a Spring application?
- AThe server processes the request with default values.
- BA 500 Internal Server Error is returned.
- CThe request is silently ignored.
- DA 400 Bad Request error is returned.
7.Which of the following is a benefit of using RFC 7807 ProblemDetail for error responses?
- AAutomatically fixes client-side errors.
- BReduces server load by caching errors.
- CProvides a standardized JSON error format.
- DEncrypts error messages for security.
8.A Spring Boot application returns a JSON error with fields like 'type', 'title', and 'status'. What feature is being used?
- ACustom exception handling
- BRFC 7807 ProblemDetail
- C@RequestBody with validation
- DResponseEntity with custom headers