nerdexam
Cisco

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.

Understanding and Using APIs

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)
  • A
    90% (44)
  • B
    4% (2)
  • C
    4% (2)
  • D
    2% (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.

AAccept: application/xml; q=0.5, application/jsonCorrect

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.

BContent-Type: application/json

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.

CContent-Type : application/xml; q=0.5, application/json

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.

DExpect: application/json

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

#REST API#HTTP Headers#Content-Type#JSON

Community Discussion

No community discussion yet for this question.

Full 200-901 Practice