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?

  1. AAccept: application/json
  2. BContent-Type: text/html
  3. 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.
Practice this topic Back to topic

Books on Web Technology Basics Ad

As an Amazon Associate I earn from qualifying purchases.

More Web Technology Basics questions

  1. A browser requests an image it received earlier once again, putting the ETag value from that earlier response into the If-None-Match header. If the image on the server has not changed, which of the following is the correct server response?
  2. Which of the following correctly describes HTTP/2 and HTTP/3?
  3. From a web server with an RTT of 40 ms, one HTML file and the four images it references are fetched one after another. Assume that establishing a TCP connection takes one round trip and each request and response take one round trip, and ignore data transfer time, server processing time, TLS and connection teardown. Which of the following is the difference in total time between opening a new TCP connection for each object and reusing one TCP connection (a persistent connection)?
  4. HTTP is a stateless protocol. Which of the following correctly describes what this means together with the usual way a website keeps a user logged in?
  5. Which of the following correctly describes the cookie set by the header above?