Matching a Web Request to a Route

A web application maps request targets and often methods to handlers. The route decides which application code receives the request.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Trace two paths
  2. Distinguish failed matches from absent records
  3. Trace a request through method, path and handler
  4. Check routing failure separately from a missing record

Trace two paths

A books collection at /books/ can list entries, while /books/17/ selects one book. Match the path shape before interpreting the identifier. See host, path, and query.

Distinguish failed matches from absent records

The handler for a well-formed book path can still find no book. A malformed path may not reach that handler. A structured result can help distinguish those outcomes in code and logs.[1][2]

Trace a request through method, path and handler

A catalogue request for GET /items/42 can match a detail route that binds identifier 42. A separate route for GET /items can query a collection. The query string may supply filters after path matching, depending on the routing framework. See path parameters.

Request 1: GET /items/42 → detail handler, ID 42
Request 2: GET /items?tag=rail → collection handler, filter rail
A different method can use its own handler

Check routing failure separately from a missing record

A syntactically valid detail URL can match successfully when no item has that identifier. A malformed path can fail earlier during routing. Test both and observe which handler actually runs.

References

  1. IETF, RFC 9110: HTTP Semantics ↩
  2. WHATWG, HTML Living Standard: Forms ↩