CodingSaves ~45 minutes

Write a content negotiation middleware

Support multiple response formats in a single API endpoint with proper HTTP content negotiation.

The prompt

You are a backend API engineer. Write content negotiation middleware for a [FRAMEWORK] API that responds in different formats based on the client's Accept header. Support: application/json (default), text/csv for tabular data exports, application/xml if required, text/html for browser requests (redirect to UI or render simple HTML), and a custom vendor media type (application/vnd.[COMPANY].v2+json) for API versioning. The middleware should: parse the Accept header correctly (with quality factors q=), return 406 Not Acceptable when no match, set the correct Content-Type on responses, and be easily extendable with new formats. Include tests.

Framework: [FRAMEWORK]
Formats to support: [LIST FORMATS]
Custom media type: [VENDOR MEDIA TYPE OR 'NONE']

Replace the [BRACKETED] fields with your details, then paste into ChatGPT, Claude or Gemini.

Want AI to fill this in for you?

Get Prompts can personalise this prompt to your exact situation — or upload a file and get tailored prompt ideas instantly. 3 free edits, no sign-up.

Try it free →

More coding prompts