ASP.NET Core Web API Interview Question #24

What is content negotiation in ASP.NET Core Web API?

Web API & REST Fundamentals, Controllers, HTTP Methods & Status Codes Junior Beginner

Quick Interview Answer

Content negotiation is the process of selecting an appropriate representation format for a response based on the endpoint capabilities and request information such as the Accept header. JSON is the normal default format for modern ASP.NET Core APIs.

Detailed Explanation

Content negotiation is the process of selecting an appropriate representation format for a response based on the endpoint capabilities and request information such as the Accept header. JSON is the normal default format for modern ASP.NET Core APIs.

Formatters and MVC options can be configured when an API needs additional formats. Public APIs should document the media types they accept and return.

Code Example

GET /api/products/10
Accept: application/json

HTTP/1.1 200 OK
Content-Type: application/json