Content Negotiation — Media Type Versioning
DodaTech
Updated 2026-06-28
1 min read
In this tutorial, you will learn about Content Negotiation. We cover key concepts, practical examples, and best practices to help you master this topic.
Content negotiation versioning uses the standard HTTP Accept header with custom media types to specify the desired API version and response format simultaneously.
Request Format
GET /api/users
Accept: application/json; version=2
Accept: application/vnd.dodatech.v2+json
Implementation
app.get("/api/users", (req, res) => {
const accept = req.headers["accept"] || "";
const version = accept.includes("version=2") ? "2.0" : "1.0";
if (version === "2.0") {
return res.json({ version: "2.0", data: usersV2 });
}
res.json({ version: "1.0", data: usersV1 });
});
Trade-offs
Pros: Uses standard HTTP mechanism, clean URLs, supports multiple formats. Cons: Complex to implement, less discoverable, harder to test.
Common Mistakes
- Not handling Accept header absence — Default to latest version.
- Ignoring quality values — Accept header can include q values for preference.
- No format negotiation — Not sending Content-Type for response format.
Practice Questions
- How does content negotiation versioning work?
- What is the role of the Accept header?
- What are the advantages of using standard HTTP mechanism?
Challenge
Implement content negotiation versioning supporting multiple media types and versions. Parse the Accept header to determine version and response format.
What's Next
In the next lesson, you will learn version formats.
← Previous
Query Parameter Versioning — Version in the URL Query
Next →
Backward Compatibility — Making Non-Breaking Changes
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro