An optional function argument lets an ASP.NET Core minimal API handler run when its input is missing. Mark a value-type parameter nullable, such as int?, so model binding supplies null instead of rejecting the request. Nullable complex parameters, such as Product?, likewise receive null when the request body is absent or contains JSON null. section 7.5
Use optional handler arguments when the endpoint should accept either form of input:
- Combine an optional route placeholder, such as /stock/{id?}, with int? so both /stock/123 and /stock invoke the handler. section 7.5
- Use a nullable reference type, such as Product?, for an optional body-bound complex value. section 7.5
- Keep the parameter nonnullable when missing input should produce a 400 Bad Request and prevent the handler from running. section 7.5
Nullable route and body arguments
app.MapGet("/stock/{id?}", (int? id) => $"Received {id}"); app.MapPost("/stock", (Product? product) => $"Received {product}"); The first endpoint accepts /stock/123 and /stock; the second accepts a missing body or JSON null and receives null. section 7.5



