Problem statement
Map two order lookups with route constraints, so a badly formed order number or tracking code is turned away by routing and never reaches the handler.
Requirements
The order store and the two handlers in OrderHandlers are already provided. Your task has one part: map the two lookups in MapOrderEndpoints in OrderLookupApi/Endpoints/OrderEndpoints.cs.
A route constraint, written as {name:constraint} in the route, decides whether a URL segment matches at all. When it does not match, routing answers 404 and the handler never runs. Without a constraint, a value that cannot become the handler's parameter type is answered with 400 instead.
OrderHandlers (provided)
- GetOrderById takes an int orderId and answers 200 with the order, or 404 when no order has that id
- GetOrderByTrackingCode takes a Guid trackingCode and answers the same way
- Each handler counts its calls, shown at GET /diagnostics/handler-invocations
OrderEndpoints
- GET /orders/{orderId} is handled by GetOrderById. Only a whole number that fits in an int matches, so abc, 12.5 and 2147483648 get a 404 from routing
- GET /orders/tracking/{trackingCode} is handled by GetOrderByTrackingCode. Only a GUID matches, so not-a-guid or a cut-off GUID gets a 404 from routing
- A well-formed value always reaches its handler, even when no order has it
Sample Requests & Responses
GET /orders/1001
Response (200 OK):
{
"orderId": 1001,
"trackingCode": "4d2a7c18-9f31-4a5b-8c6d-1e2f3a4b5c6d",
"customer": "Dana Whitfield",
"status": "Shipped",
"total": 149.95
}
GET /orders/tracking/4d2a7c18-9f31-4a5b-8c6d-1e2f3a4b5c6d
Response (200 OK), with the same order.
GET /orders/abc and GET /orders/tracking/not-a-guid
Response (404 Not Found) for each, from routing.
GET /diagnostics/handler-invocations after the four requests above
Response (200 OK), showing that only the two well-formed requests reached a handler:
{ "orderById": 1, "orderByTrackingCode": 1 }
