Bird
0
0

Given the code snippet:

medium📝 component behavior Q13 of 15
Spring Boot - REST Controllers
Given the code snippet:
return ResponseEntity.status(HttpStatus.CREATED)
    .header("Location", "/items/123")
    .body("Item created");

What will be the HTTP status and headers in the response?
AStatus 201 Created with no headers
BStatus 201 Created with header Location: /items/123
CStatus 200 OK with header Location: /items/123
DStatus 404 Not Found with header Location: /items/123
Step-by-Step Solution
Solution:
  1. Step 1: Analyze status method

    The code sets status to HttpStatus.CREATED which is 201.
  2. Step 2: Analyze header method

    The header method adds a "Location" header with value "/items/123".
  3. Final Answer:

    Status 201 Created with header Location: /items/123 -> Option B
  4. Quick Check:

    Status = 201, Header Location set [OK]
Quick Trick: status() sets code, header() adds headers [OK]
Common Mistakes:
  • Assuming default 200 OK status
  • Forgetting headers are added by header()
  • Confusing status codes meanings

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes