IResult represents the result produced by executing an ASP.NET Core HTTP endpoint. Endpoint handlers can return different responses through the same interface, such as successful content or a 404 response, without using exceptions for expected failure. section 3.1.2
A practical endpoint can use IResult to:
- Return generated text with Results.Content when an operation succeeds. section 3.1.2
- Return Results.NotFound when AsciiArt.Write reports that the requested font is invalid. section 3.1.2
- Return image bytes with Results.File and an image/jpeg content type. section 3.1.2
Listing 3.16 Returning 404 if font is invalid
app.MapGet("/{text}",
(string text, string? font) =>
AsciiArt.Write(text, out var asciiText, font) #1
? Results.Content(asciiText!) #2
: Results.NotFound()); #3
This focused endpoint uses a ternary operator because Results.Content and Results.NotFound both produce IResult values. section 3.1.2
Content or 404
AsciiArt.Write(text, out var asciiText, font) ? Results.Content(asciiText!) : Results.NotFound() section 3.1.2

