BadHttpRequestException indicates that a minimal API could not create an endpoint argument from the HTTP request. ASP.NET Core returns a 400 Bad Request response instead of calling the handler. section 7.11 section 7.2
Expect this failure when model binding cannot produce every handler parameter, including when:
- A simple value such as an int cannot be parsed from a route value, query string value, or header. section 7.11 section 7.2
- A required value is missing from the request. section 7.11
- A custom type's TryParse method returns false. section 7.11
- A request attempts unsupported or unexpected body binding, such as binding a GET body or accessing form values through model binding. section 7.11
A strongly typed route value
An endpoint can accept a ProductId instead of a raw string when the type exposes TryParse. For /product/p123, successful parsing creates the handler argument; an invalid value produces a 400 response. section 7.2
Figure 7.3 The routing middleware matches the incoming URL to the endpoint. The endpoint middleware attempts to bind the route parameter id to the endpoint parameter. The endpoint parameter type ProductId implements TryParse. If parsing is successful, the parsed parameter is used to call the endpoint handler. If parsing fails, the endpoint middleware returns a 400 Bad Request response.
Follow the request path from route matching through TryParse and handler invocation, including the failure path that returns 400 Bad Request. section 7.2
