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
