DevNet Associate (DEVASC) v1.0Understanding and Using APIsMedium
A network automation script needs to retrieve a list of all interfaces on a Cisco device using its REST API. The API documentation specifies the endpoint `/restconf/data/interfaces` and requires the `Accept` header to be set to `application/yang-data+json`. Which `cURL` command would correctly perform this request?
- A`curl -X GET -H "Content-Type: application/json" https://device/restconf/data/interfaces`
- B`curl -X POST -H "Accept: application/yang-data+json" https://device/restconf/data/interfaces`
- C`curl -X GET -H "Accept: application/yang-data+json" https://device/restconf/data/interfaces`
- D`curl -X GET -H "Accept: application/json" -H "Content-Type: application/yang-data+json" https://device/restconf/data/interfaces`
Show answer & explanationAnswer & explanation
Correct answer: C. `curl -X GET -H "Accept: application/yang-data+json" https://device/restconf/data/interfaces`
To retrieve data, a `GET` request is used. The documentation explicitly states the `Accept` header should be `application/yang-data+json` to specify the desired response format. Option C correctly combines these requirements.
Why the other options are wrong
- A. Uses `Content-Type` instead of `Accept` for specifying the desired response format.
- B. Uses `POST` instead of `GET` for retrieving data, which is incorrect.
- D. Incorrectly uses `Content-Type` for the desired response format and includes an unnecessary `Accept: application/json`.
cURL GET Request with Accept Header
A cURL command to retrieve data from an API endpoint, specifying the desired response media type using the 'Accept' HTTP header.
- Uses `-X GET` for the HTTP method.
- Uses `-H "Accept: <media_type>"` to request a specific response format.
- Essential for APIs that support multiple output formats (e.g., JSON, XML, YANG+JSON).
Memory trick: cURL Commands Make REST Easy, Just Get Headers Right.