The Problem No One Talks About
- Separate endpoints like /api/products/123.md - duplicates your routing, drifts out of sync, and forces clients to know about a non-standard URL scheme.
- Markdown-only pages - breaks the experience for humans.
Content Negotiation, The Way HTTP Intended
How It Works Under the Hood
- Request comes in with Accept: text/markdown
- If a configured route matches, rewrite to /md-api/...
- Catch-all handler runs your Markdown function
- Respond with 200 text/markdown
Setup in 3 Steps
1. Install
Bash
Bash
2. Define Your Markdown Versions
Ts
3. Wire Up Rewrites
Ts
Ts
Why This Matters
- Fewer tokens consumed - you're not burning context window on script tags and hydration data
- Better extraction accuracy - no parsing HTML soup to find the three fields that matter
- Faster responses - less data over the wire, less processing on the model side
- Single source of truth - one URL, one routing layer, multiple representations
- No drift - your Markdown definitions live next to your page definitions
- Standard HTTP - any client that sets an Accept header gets the right format
Middleware Alternative
Ts
Try It
Bash
The repo is MIT-licensed and works with both App Router and Pages Router.
GitHub: github.com/kasin-it/next-md-negotiate
Bash
