DevNet Associate (DEVASC) v1.0Understanding and Using APIsHard

A network automation script needs to retrieve a list of all active interfaces on a Cisco device using its REST API. The API supports various response formats, including XML and JSON. The script specifically requires the response to be in JSON. Which HTTP header should be included in the GET request to explicitly request a JSON response?

  1. A`Accept: application/json`
  2. B`Content-Type: application/json`
  3. C`Transfer-Encoding: application/json`
  4. D`Content-Encoding: application/json`
Show answer & explanation

Correct answer: A. `Accept: application/json`

The `Accept` HTTP header is used by the client to tell the server which media types it can understand or prefers for the response. To request a JSON response, the `Accept` header should be set to `application/json`. `Content-Type` is for the request body, not the desired response format.

Why the other options are wrong

  • B. `Content-Type` specifies the media type of the *request body* being sent to the server, not the desired *response format* from the server.
  • C. `Transfer-Encoding` specifies the form of encoding used to safely transfer the message body, distinct from the media type.
  • D. `Content-Encoding` specifies the encoding (e.g., gzip, deflate) applied to the message body, not its format.

HTTP Accept Header

The `Accept` HTTP header is a client-side header used to inform the server about the media types (e.g., `application/json`, `application/xml`) that the client can process and prefers to receive in the response.

  • Sent by the client in a request.
  • Indicates preferred response format.
  • Differs from `Content-Type` (which describes the request body).
  • Server tries to send a response in one of the accepted formats.

Memory trick: Accept what you want, Content is what you send.

More Understanding and Using APIs questions