What does the request header Content-Type: application/json tell the server?
Options
- The client wants JSON back in the response
- The body of this request is formatted as JSON (Correct option)
- The request is encrypted before it is sent
- The user is already logged in
Answer
The body of this request is formatted as JSON
Why
Content-Type describes the format of the body being SENT. With application/json the server knows to parse the body as JSON.
To say which format you want BACK, the client uses the Accept header.
If the header is wrong or missing, many frameworks reject or misread the body.
Remember
Content-Type = format of what I send. Accept = format I want back.