Interview frequency: …
Short answer
It lets the client specify a preferred data format (such as JSON or XML) through Accept, while Content-Type declares the format of the data actually being sent.
Explanation
When a client sends Accept: application/json, text/csv;q=0.8, the server negotiates the best supported format using the quality factor (q-factor). In Node.js, checking request headers and responding with the correct Content-Type ensures standards compliance across clients and avoids parsing errors.
Code example
const accept = req.headers["accept"] || "";
if (accept.includes("application/json")) {
res.setHeader("Content-Type", "application/json");
res.end(JSON.stringify(data));
}Common mistakes
- Ignoring the request's Content-Type header and trying to parse the body as JSON when it is plain text or multipart data.