DevNet Associate (DEVASC) v1.0Understanding and Using APIsMedium
A developer is using Postman to test a new REST API endpoint that requires sending a JSON payload in the request body. After configuring the request, they receive an HTTP 415 Unsupported Media Type error. Which of the following actions should the developer take to resolve this issue?
- AChange the HTTP method from POST to GET.
- BAdd an 'Accept: application/json' header.
- CReduce the size of the JSON payload.
- DSet the 'Content-Type: application/json' header.
Show answer & explanationAnswer & explanation
Correct answer: D. Set the 'Content-Type: application/json' header.
An HTTP 415 Unsupported Media Type error indicates that the server does not accept the format of the request payload. Setting the 'Content-Type: application/json' header correctly informs the server that the request body contains JSON data.
Why the other options are wrong
- A. Changing the HTTP method would alter the request's intent and is unrelated to media type issues.
- B. The 'Accept' header specifies what the client *wants to receive*, not what it *is sending*.
- C. Payload size is typically related to 413 Payload Too Large errors, not 415 Unsupported Media Type.
HTTP 415 Unsupported Media Type
The HTTP 415 status code indicates that the server refuses to accept the request because the payload format is not supported by the server for this method and resource.
- Server doesn't understand request body format.
- Often resolved by setting 'Content-Type' header.
- Common with POST/PUT requests using JSON/XML.
Memory trick: 415 means the server can't 'digest' your data type.