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

A network engineer wants to retrieve a list of all active interfaces on a Cisco device using its REST API. The API endpoint is `/restconf/data/ietf-interfaces:interfaces`. They need to ensure that the response is returned in a human-readable, structured format. Which HTTP `Accept` header value should be included in the request to achieve this, assuming the API supports both XML and JSON?

  1. A`text/plain`
  2. B`application/json`
  3. C`*/*`
  4. D`application/xml`
Show answer & explanation

Correct answer: B. `application/json`

The `Accept` header tells the server which media types the client can process. For a human-readable, structured format, `application/json` is commonly preferred over `application/xml` due to its widespread use and ease of parsing in modern applications. The question implies the API supports both, making JSON a strong choice for 'human-readable, structured'.

Why the other options are wrong

  • A. `text/plain` is for unformatted text, not a structured format.
  • C. `*/*` is a wildcard that accepts any media type, not specifically requesting a human-readable structured format like JSON or XML.
  • D. `application/xml` is a structured format, but `application/json` is generally considered more lightweight and commonly used for human-readable structured data in modern APIs.

HTTP Accept Header

An HTTP request header that specifies which media types the client is able to understand and process in the server's response.

  • Used for content negotiation, allowing clients to request preferred response formats.
  • Common values include `application/json`, `application/xml`, `text/html`.
  • Servers will try to respond with one of the requested types, or default if no match.

Memory trick: Tell the chef how you like your data served: JSON, XML, or plain text.

More Understanding and Using APIs questions