QuizzesREST Controllers — Concept Check
intermediate
spring-boot

REST Controllers — Concept Check

Questions on REST Controllers. @RestController combines @Controller and @ResponseBody — every method returns data serialized directly to the response body, not a view name. This is the building block of every Spring Boot REST API.

8 minutes 8 questions Pass at 70%
Time Limit
8 minutes - timer starts when you begin
Change Answers Freely
Revisit and change any answer before submitting
Full Review After Submit
Correct answers and explanations shown for every question
Auto-submit on timeout
Quiz submits automatically when time runs out

Questions in this quiz

8 questions on REST Controllers — Concept Check. Work through them here, then start the quiz to answer them and see your score.

  1. 1.A developer is implementing a new endpoint in a Spring Boot application. Which annotation should they use to ensure the method's return value is serialized directly to the HTTP response body as JSON?

    • A@ResponseBody
    • B@RestController
    • C@Controller
    • D@JsonSerialize
  2. 2.You have a Spring Boot REST API with a method annotated with @GetMapping. What is the default format for the method's return value?

    • AXML
    • BHTML
    • CPlain Text
    • DJSON
  3. 3.A REST controller method is returning a 204 No Content status. Which return type is likely used in the method?

    • AResponseEntity<UserDto>
    • BUserDto
    • CResponseEntity<Void>
    • Dvoid
  4. 4.A developer needs to handle a request with a dynamic URL segment in a Spring Boot application. Which annotation should they use to extract the segment?

    • A@RequestHeader
    • B@PathVariable
    • C@RequestParam
    • D@RequestBody
  5. 5.A team is designing a REST API and wants to control HTTP status codes and headers in responses. Which return type should they use?

    • AResponseEntity
    • BUserDto
    • Cvoid
    • DString
  6. 6.A developer mistakenly believes that using @Controller alone will automatically serialize return values to JSON. What is the correct approach?

    • AUse @Controller with @RequestBody
    • BUse @ResponseBody with @Controller
    • CAdd @JsonSerialize to methods
    • DUse @RestController instead
  7. 7.In a Spring Boot application, a method is annotated with @GetMapping and returns a List<UserDto>. What does the DispatcherServlet do with this return value?

    • AConverts it to JSON using MessageConverter
    • BIgnores it and returns 204 No Content
    • CReturns it as plain text
    • DRenders it as an HTML view
  8. 8.A developer is using @RequestParam to handle query parameters. Which feature allows them to specify a fallback value if the parameter is missing?

    • AdefaultValue attribute
    • Brequired attribute
    • C@RequestHeader
    • D@PathVariable