A 400 Bad Request response tells an HTTP client that its request was invalid, commonly because submitted data failed validation or could not be parsed. section 5.3.1 section 5.6
Minimal APIs can produce this response when:
- A client sends an incompatible value, such as the string "two" for an integer parameter. section 7.2
- A required parameter cannot bind from the selected route, query-string, header, or body source. section 7.8
- An endpoint deliberately rejects invalid application data with Results.BadRequest or a typed result. section 5.3.1
Rejecting a duplicate resource
A POST endpoint attempts to add a fruit. If the identifier already exists, it returns Results.BadRequest with an explanatory error; otherwise, it returns 201 Created. section 5.3.1
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 binding flow from route matching through TryParse; unsuccessful parsing ends in a 400 response before the handler runs. section 7.2

