Bird
0
0

You want your REST API to support both JSON and XML responses. Which server-side approach correctly implements content negotiation?

hard📝 Application Q15 of 15
Rest API - Request and Response Format
You want your REST API to support both JSON and XML responses. Which server-side approach correctly implements content negotiation?
AIgnore the Accept header and always send JSON
BSend both JSON and XML in the same response body
CCheck the Accept header and respond with JSON or XML accordingly
DRespond with XML only if the client sends a custom header
Step-by-Step Solution
Solution:
  1. Step 1: Understand content negotiation best practice

    The server should read the Accept header to decide response format.
  2. Step 2: Choose approach matching client preference

    Responding with JSON or XML based on Accept header is correct behavior.
  3. Final Answer:

    Check the Accept header and respond with JSON or XML accordingly -> Option C
  4. Quick Check:

    Content negotiation = respond per Accept header [OK]
Quick Trick: Always respect Accept header to choose response format [OK]
Common Mistakes:
  • Ignoring Accept header and hardcoding response
  • Sending multiple formats in one response
  • Using unrelated custom headers for format choice

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes