Each host contains matching rules for the host along with optional constraints, and a list of routes for the path component.
The list of routes for the path component is defined similar to the list of hosts.
string()
or a binary()
.Hosts with and without a trailing dot are equivalent for routing. Similarly, hosts with and without a leading dot are also equivalent.
:
character means that what follows until the end of the segment
is the name of the binding in which the segment value will be stored._
binding will succeed
but the data will be discarded. This is especially useful for
matching against many domain names in one go.Similarly, it is possible to have optional segments. Anything between brackets is optional.
You can also have imbricated optional segments.
cowboy_req:host_info/1
and cowboy_req:path_info/1
respectively.
They will be represented as a list of segments.If a binding is defined in both the host and path, then they must also share the same value.
Finally, there are two special match values that can be used. The
first is the atom '_'
which will match any host or path.
The second is the special host match "*"
which will match the
wildcard path, generally used alongside the OPTIONS
method.
To compile routes, just call the appropriate function: