EasyπŸ‘€ 0-2 yearsπŸ‘€ 3-5 years 1 min read

How does HTTP content negotiation work (Accept vs Content-Type)?

Asked inInfosysAccentureDeloitte
#content negotiation#accept#content-type#media type
Report issue

⚑ Short Answer

Content-Type describes the body the sender is providing; Accept tells the server what the client wants back. The server picks a representation matching Accept (or returns 406 Not Acceptable). This also powers media-type API versioning.

β˜•Coffee Chat Question

Concept Made Simple

β€œHow does HTTP content negotiation work (Accept vs Content-Type)?”

🧠Mind Map Answer

Remember It Faster

Content-Type→format of THIS request/response body
Accept→formats the client will accept back
406β†’server can't meet the Accept
415β†’server can't read the Content-Type

πŸ”₯What If?

Think Beyond the Expected

A client gets 415 Unsupported Media Type on a POST β€” what's wrong?

The client sent a body in a format the endpoint doesn't accept (or omitted/typo'd Content-Type, e.g. sending JSON without Content-Type: application/json). Set the correct Content-Type so the server picks the right parser.

πŸ˜‚Real World

Content negotiation underlies returning JSON vs CSV from the same endpoint and media-type versioning (application/vnd.myapi.v2+json); 415/406 errors are everyday API debugging.

🎯Interviewer's Expectation

Keywords they're listening for:

βœ“ Content-Type = body formatβœ“ Accept = desired responseβœ“ 406 vs 415βœ“ media-type versioning

⚠️Common Mistakes

  • βœ—Omitting Content-Type on JSON POSTs
  • βœ—Confusing Accept with Content-Type
  • βœ—Returning 400 where 415/406 fits

βœ…Best Practices

  • βœ“Always set Content-Type on requests with a body
  • βœ“Use Accept for negotiation
  • βœ“Return precise 406/415 codes

πŸ”Follow-up Questions

  • 1406 vs 415 β€” which is which?
  • 2How does media-type versioning use Accept?
  • 3How would you serve both JSON and CSV from one endpoint?

🧩Related Technologies

media typesSpring @RequestMapping produces/consumesvendor media types

Continue Learning with AI

Take this question deeper with your favourite AI assistant. Pick a depth, copy the prompt, or open it directly β€” AI is your learning companion, not a shortcut.

Plain-language foundations

I'm preparing for a software engineering interview and want to understand this from scratch, as a beginner.

Topic: HTTP Methods (REST APIs)
Interview question: "How does HTTP content negotiation work (Accept vs Content-Type)?"

Please:
1. Explain the core idea in simple, plain language, using an everyday analogy.
2. Define any technical terms you use.
3. Walk through one small, concrete example.
4. Finish with a single sentence I can easily remember.

Keep the tone friendly and assume I'm new to this topic.

Was this answer helpful?

Support our platform by exploring our recommended products.

As an Amazon affiliate, purchases through these links may earn us a small commission β€” at no extra cost to you. It helps keep Full Stack Interview Guru free.

Related Questions