Skip to main content

Module router

Module router 

Source
Expand description

Route matching.

The Router owns the compiled set of mock routes and answers the question “given this request, which route matches and what should the response be?”.

§Matching algorithm

Routes are evaluated in declaration order; the first matching route wins. A route matches when:

  1. the HTTP Method equals the request method,
  2. the path pattern matches the request path segment by segment (capturing {param} segments), and
  3. every rule in the optional when block (RequestMatch) is satisfied: required query parameters, headers (case-insensitively) and a JSON body subset.

Structs§

Match
The result of matching a request against the Router.
Router
A compiled set of routes ready to answer requests.

Enums§

PathError
Errors in an individual path pattern.
RouterError
Errors that can occur while building a Router.