DevNet Associate (DEVASC) v1.0Understanding and Using APIsEasy
A network operations team is developing an automation script to provision VLANs on multiple Cisco switches using a REST API. The script needs to create a new VLAN by sending a POST request to a `/vlan` endpoint with a JSON payload containing the VLAN ID and name. Which `Content-Type` header value should be included in the HTTP request to correctly inform the API about the payload format?
- Amultipart/form-data
- Bapplication/x-www-form-urlencoded
- Ctext/plain
- Dapplication/json
Show answer & explanationAnswer & explanation
Correct answer: D. application/json
When sending a JSON payload in an HTTP request body, the `Content-Type` header must be set to `application/json` to inform the server that the body contains JSON data. This allows the server to correctly parse the incoming data.
Why the other options are wrong
- A. `multipart/form-data` is used for sending large binary data or multiple parts, like file uploads.
- B. `application/x-www-form-urlencoded` is for form data, typically key-value pairs encoded in the URL or body.
- C. `text/plain` is for unformatted text, not structured JSON data.
HTTP Content-Type Header
An HTTP header that indicates the media type of the resource in the request or response body, specifying how the content should be parsed or interpreted.
- Crucial for correct interpretation of data exchanged between client and server.
- Examples include `application/json`, `text/html`, `image/jpeg`.
- Used in both request (for body sent to server) and response (for body sent to client).
Memory trick: Label your package (data) so the post office (server) knows how to handle it.