200-901 · Question #506
The API documentation has this requirement for a REST API request: "For methods that accept request parameters, the platform accepts either application/json or application/x-www-form-urlencoded…
The correct answer is A. Accept: application/xml; q=0.5, application/json. The HTTP Accept header is used by a client to declare which response content types it will accept, ensuring the server returns data in the preferred format.
Question
The API documentation has this requirement for a REST API request:
"For methods that accept request parameters, the platform accepts either application/json or application/x-www-form-urlencoded content types and currently only supports returning data in application/json format." Which field returns content in the required format? A. B. C. D.
Options
- AAccept: application/xml; q=0.5, application/json
- BContent-Type: application/json
- CContent-Type : application/xml; q=0.5, application/json
- DExpect: application/json
How the community answered
(49 responses)- A90% (44)
- B4% (2)
- C4% (2)
- D2% (1)
Why each option
The HTTP Accept header is used by a client to declare which response content types it will accept, ensuring the server returns data in the preferred format.
The Accept header 'Accept: application/xml; q=0.5, application/json' tells the server the client prefers application/json (implicit q=1.0) over application/xml (q=0.5), so the server - which only supports returning JSON - will respond with application/json. This is the correct HTTP content negotiation mechanism for controlling the response format. The other entries use Content-Type, which controls the request body format, not the response format.
Content-Type describes the format of the data the client is sending in the request body; it has no effect on the format of the server's response.
Content-Type with an XML preference still controls only the outgoing request body format, and specifying XML would conflict with the server's JSON-only response capability.
The Expect header is used for handshake behaviors such as 100-continue and is not a content negotiation mechanism for specifying response media types.
Concept tested: HTTP Accept header content negotiation
Source: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept
Topics
Community Discussion
No community discussion yet for this question.