An API model is the data returned by an API action for serialization and transmission to a client. Unlike a view model or PageModel, it normally contains response data rather than metadata describing how to generate a response. section 20.2 section 20.7
The action creates the API model after application logic supplies the required data. An output formatter then serializes it into a machine-readable representation such as JSON or XML, and the response continues through the middleware pipeline to the caller. section 20.2 section 20.0
API actions can shape their result in two common ways:
- Return data directly when the action has a straightforward response. section 20.7
- Return ActionResult<T> when the action may produce more than one result type, such as data or an error response. section 20.7
Returning fruit data
An action handling an apples category can receive fruit objects from the application model, place that data in an API model, and return it. The output formatter can serialize the result as JSON; content negotiation can select another supported format, such as XML, when the client requests it. section 20.2 section 20.0
Figure 20.6 A call to a web API endpoint in an e-commerce ASP.NET Core web application. The ghosted portion of the diagram is identical to figure 20.5.
Use the request-flow diagram to follow how an API endpoint transforms application data into a response for its client. section 20.2


