The most basic path is
/ which will simple match the root path. You can add
other static paths like
Path-to-regex supports dynamic matching including a feature that will parameterize parts of the URL. For example:
/products/:productId/sizes/:size will match the following paths
/products/pizza/size/small and set the params object on
Query-strings (or search parameters) will not affect path matching.
Regular Expressions and Wildcards#
You can also use regular expressions in your paths. They must be contained in
() to indicate to
path-to-regexp that they are regex.
/(.*) will match anything.
This is a true wildcard route and can be used for custom 404s by making this the last route in your OpenAPI file (and matching all methods).
/(a?b) will match either
/main/(a|b) will match
/icon-(\d++).png will match
/icon-1234.png or any other series of
digits for 1234.
You can also name your regexp groups so that they appear as named parameters.
products/:productId/icons/icon-:imageIndex(\d+).png will match
/products/pizza/icons/icon-2.png and produce a
request.params object as
Note that not all regex features are available, us of the following will either be ignored or result in an error, including
(?:...)- named matches
$- start or end of string
[abc]- character classes
There is a simple
route tester available
that can be used to debug route matching with