liveBook · Manning

ExecuteAsync

As explained in ASP.NET Core in Action, 3e

ExecuteAsync is the method that an IResult implementation uses to write its configured result to an HTTP response.

ExecuteAsync is the method an IResult implementation uses to write its configured result to an HTTP response. Returning IResult lets a minimal API endpoint control the response instead of relying on default serialization. section 5.3

Minimal API endpoint middleware handles returned values in different ways:

  • void or Task produces a 200 response with no body. section 5.3
  • string or Task<string> produces a 200 response with a text/plain body. section 5.3
  • IResult or Task<IResult> invokes ExecuteAsync, allowing the implementation to choose the response behavior and status code. section 5.3
  • Other values, such as POCOs, are serialized as JSON in a 200 application/json response. section 5.3

Choosing an IResult for a missing resource

A fruit lookup that cannot find the requested identifier can return an IResult representing 404 Not Found instead of throwing an exception. ExecuteAsync then writes that result to the HTTP response. section 5.3

How ASP.NET Core in Action, 3e covers it

How deep it goes
Explains dispatch among endpoint return types and response effects, but does not detail ExecuteAsync implementation internals.
Examples
Uses void, strings, POCOs, IResult, and a missing-fruit lookup that returns 404 Not Found.
What it assumes
Assumes familiarity with minimal API endpoint handlers and distinguishes IResult from strings, Tasks, and JSON-serialized objects.
What you can do after
Apply it by returning IResult when an endpoint needs explicit status codes or response customization.
How it connects
Connects IResult with minimal APIs, endpoint handlers, HTTP status codes, and JSON serialization.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of ASP.NET Core in Action, 3e. The section links point to the parts of the book it draws on.