Web Technology Basics
A web API returns data in JSON format as the body of its response. Which of the following headers is generally added to the response to indicate the format of the body?
- AAccept: application/json
- BContent-Type: text/html
- CContent-Type: application/json
Show answer and explanation
Answer: C. Content-Type: application/json
The kind of data in the body is indicated by the Content-Type header, whose value is a media type (MIME type) in the form "type/subtype", such as text/html or image/png. The media type of JSON is application/json. JSON is a text format that represents data with name-value pairs and arrays, as in {"id": 42, "tags": ["a", "b"]}; it is more concise than XML and easy to handle from JavaScript, so it is widely used in web APIs. The Accept header is used in a request to tell the server which formats the client wants to receive.
- A. Accept is a request header that tells the server which formats the client wants to receive. The format of a response body is indicated by Content-Type.
- B. text/html indicates that the body is an HTML document. JSON uses application/json.
- C. Correct. The media type of JSON is application/json.