Bird
0
0

Given this Spring Boot controller method:

medium📝 component behavior Q13 of 15
Spring Boot - Request and Response Handling
Given this Spring Boot controller method:
public ResponseEntity getData() {
    return ResponseEntity.ok()
        .header("X-Rate-Limit", "1000")
        .header("X-Request-ID", "abc123")
        .body("Success");
}

What headers will the client receive in the response?
ANo custom headers, only body 'Success'
BOnly X-Rate-Limit: 1000
COnly X-Request-ID: abc123
DX-Rate-Limit: 1000 and X-Request-ID: abc123
Step-by-Step Solution
Solution:
  1. Step 1: Analyze header() calls in method

    Two header() calls add "X-Rate-Limit" with "1000" and "X-Request-ID" with "abc123".
  2. Step 2: Confirm both headers are included in response

    ResponseEntity accumulates headers, so both custom headers are sent with the response.
  3. Final Answer:

    X-Rate-Limit: 1000 and X-Request-ID: abc123 -> Option D
  4. Quick Check:

    Multiple header() calls add multiple headers [OK]
Quick Trick: Multiple header() calls add all headers to response [OK]
Common Mistakes:
  • Assuming only last header() call applies
  • Thinking headers overwrite each other
  • Ignoring headers and focusing on body only

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes