liveBook · Manning

Content negotiation

As explained in Pro ASP.NET Core 7, Tenth Edition

Content negotiation is the process of selecting a response representation by comparing client-specified format preferences with the formats an HTTP server can produce.

Content negotiation selects a response representation by comparing the client’s Accept header with formats ASP.NET Core MVC can produce. JSON is the default, so an application configured only for JSON returns JSON even when the client requests XML. section 20.4.2

Configure and verify negotiation in an ASP.NET Core web service:

  • Return a serializable response object rather than an Entity Framework Core entity whose interface-based navigation properties may defeat XML serialization. section 20.4.2

Requesting XML

A GET request to /api/content/object with Accept: application/xml returns Content-Type: application/xml and an XML ProductBindingTarget containing the product fields. With only JSON configured, the same request returns application/json instead.

How Pro ASP.NET Core 7, Tenth Edition covers it

How deep it goes
Explains Accept-header behavior, formatter registration, serialization constraints, fallback requests, and 406 handling.
Examples
Demonstrates PowerShell requests for XML, wildcard fallback, and PNG, with observed JSON, XML, and 406 responses.
What it assumes
Assumes HTTP Accept headers and ASP.NET Core MVC, while demonstrating formatter setup and XML-serialization constraints.
What you can do after
Operate/configure ASP.NET Core MVC to add XML output, test Accept preferences, and control unsupported-format behavior.
How it connects
Connects HTTP Accept headers with ASP.NET Core MVC formatters, JSON, XML, and Entity Framework Core serialization.

Also explained in

Compare how 3 books explain content negotiation →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Pro ASP.NET Core 7, Tenth Edition. The section links point to the parts of the book it draws on.