Spring Boot REST API Development
Test your knowledge of building REST APIs with Spring MVC: controllers, request mapping, validation, and error handling.
Questions in this quiz
10 questions on Spring Boot REST API Development. Work through them here, then start the quiz to answer them and see your score.
1.What is the difference between @Controller and @RestController?
- A@RestController = @Controller + @ResponseBody on every method
- B@Controller returns JSON, @RestController returns HTML
- C@RestController can only handle GET requests
- DThey are identical — just two names for the same thing
2.Which annotation maps a method to handle HTTP DELETE at /users/{id}?
@RestController @RequestMapping("/users") public class UserController { // Which annotation goes here? public ResponseEntity<Void> deleteUser(@PathVariable Long id) { userService.delete(id); return ResponseEntity.noContent().build(); } }- A@RequestMapping(method = DELETE)
- B@PostMapping(value = "/{id}", method = DELETE)
- C@DeleteMapping("/{id}")
- D@RemoveMapping("/{id}")
3.What does @RequestBody do?
- ADeserialises the HTTP request body into a Java object
- BValidates the Content-Type header
- CSerialises a Java object into the response body
- DReads a query parameter named "body"
4.Which annotation triggers Bean Validation on a @RequestBody object?
- A@Validated(Class.class)
- B@NotNull
- C@RequestBodyValid
- D@Valid or @Validated
5.What HTTP status does ResponseEntity.created(uri).build() return?
- A204 No Content
- B200 OK
- C202 Accepted
- D201 Created
6.What is the purpose of @ControllerAdvice?
- ADefines global exception handlers and model attributes across all controllers
- BValidates all incoming requests before they reach controllers
- CAdds security advice around controller methods
- DCaches controller responses automatically
7.Which annotation extracts a value from the URL path like /products/{category}?
- A@PathVariable
- B@RequestParam
- C@MatrixVariable
- D@RequestHeader
8.What does @CrossOrigin do?
- AConfigures SSL cross-certificate validation
- BEnables Cross-Origin Resource Sharing (CORS) for the annotated controller or method
- CAllows cross-database queries
- DEnables cross-service communication
9.How do you read a request header named X-Request-ID in a controller method?
- AHttpServletRequest.getHeader("X-Request-ID")
- B@PathVariable("X-Request-ID") String requestId
- C@RequestParam("X-Request-ID") String requestId
- D@RequestHeader("X-Request-ID") String requestId
10.What is content negotiation in Spring MVC?
- ASpring compresses responses larger than a threshold
- BSpring picks the response format (JSON/XML) based on the Accept header or URL extension
- CSpring caches responses and negotiates staleness with clients
- DSpring validates the Content-Type of incoming requests