content-negotiation

Configure ASP.NET Core Web API responses based on Accept headers and registered formatters.

4|1|Updated Mar 15, 2026
One-click install
npx skills add https://github.com/FaysilAlshareef/dotnet-ai-kit --skill content-negotiation
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: content-negotiation
Source: https://github.com/FaysilAlshareef/dotnet-ai-kit/tree/main/skills/api/content-negotiation
Command: npx skills add https://github.com/FaysilAlshareef/dotnet-ai-kit --skill content-negotiation

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

APIs often return the wrong content type or fail to support client preferences, causing integration friction and brittle clients; this skill ensures responses match client Accept headers and supported formatters for consistent interoperability.

Core Features & Use Cases

  • Respect Accept headers: Choose response format (JSON, XML, CSV, etc.) based on client preferences and registered formatters.
  • Consistent error reporting: Produce RFC-compliant application/problem+json responses via ProblemDetails middleware.
  • Extensible formatters: Add custom output formatters for CSV, PDF, or other export formats and map URL/query-based format selections.
  • Use Case: Enable an ASP.NET Core API to serve legacy XML consumers, modern JSON clients, and CSV exports for reporting while returning standardized ProblemDetails for errors.

Quick Start

Configure your API to register JSON and XML formatters, add ProblemDetails, and register any custom output formatter so endpoints respond correctly to Accept headers.

Frequently Asked Questions about content-negotiation

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I configure ASP.NET Core Web API to return JSON, XML, or CSV based on the Accept header?

To configure Accept header content negotiation in ASP.NET Core, you register output formatters for JSON, XML, and CSV. This ensures the API automatically selects the correct response format based on client preferences.

What is the best way to standardize API error responses in ASP.NET Core?

Standardizing API error responses is best achieved using ProblemDetails middleware to produce RFC-compliant application/problem+json payloads. This ensures consistent error reporting across all endpoints for client interoperability.

Can I add a custom output formatter to export PDF files from my ASP.NET Core API?

Yes, you can add custom output formatters to an ASP.NET Core API to support PDF exports. By registering custom formatters, endpoints can serve PDF files alongside JSON and XML based on incoming Accept headers.

How do I map URL query parameters to control API response formats?

You can map URL query parameters to control API response formats by configuring route constraints alongside registered output formatters. This allows clients to explicitly request JSON, XML, or CSV outputs using query string selections.

Why does my ASP.NET Core API return the wrong content type for legacy XML consumers?

An ASP.NET Core API returns the wrong content type when output formatters are not properly registered. Applying content negotiation ensures responses match client Accept headers for both legacy XML and modern JSON consumers.

Do I need to configure JSON serialization options separately when implementing content negotiation?

Yes, implementing content negotiation requires configuring JSON serialization options while registering output formatters. This ensures proper format handling and prevents integration friction when serving multiple content types.