2016-01-14 13:35:25 +01:00
|
|
|
= cowboy_router(3)
|
|
|
|
|
|
|
|
== Name
|
|
|
|
|
|
|
|
cowboy_router - router middleware
|
|
|
|
|
|
|
|
== Description
|
2014-07-06 13:10:35 +02:00
|
|
|
|
|
|
|
The `cowboy_router` middleware maps the requested host and
|
|
|
|
path to the handler to be used for processing the request.
|
|
|
|
It uses the dispatch rules compiled from the routes given
|
|
|
|
to the `compile/1` function for this purpose. It adds the
|
|
|
|
handler name and options to the environment as the values
|
|
|
|
`handler` and `handler_opts` respectively.
|
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
=== Environment input
|
2014-07-06 13:10:35 +02:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
dispatch = dispatch_rules():: Dispatch table.
|
2014-07-06 13:10:35 +02:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
=== Environment output
|
2014-07-06 13:10:35 +02:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
handler = module():: Handler module.
|
|
|
|
handler_opts = any():: Handler options.
|
2014-07-06 13:10:35 +02:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
== Types
|
2014-07-06 13:10:35 +02:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
=== bindings() = [{atom(), binary()}]
|
2014-07-06 13:10:35 +02:00
|
|
|
|
|
|
|
List of bindings found during routing.
|
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
=== dispatch_rules() - opaque to the user
|
2014-07-06 13:10:35 +02:00
|
|
|
|
|
|
|
Rules for dispatching request used by Cowboy.
|
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
=== routes() = [{Host, Paths} | {Host, cowboy:fields(), Paths}]
|
2014-07-06 13:10:35 +02:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
With types:
|
2014-07-06 13:10:35 +02:00
|
|
|
|
|
|
|
* Host = Path = '_' | iodata()
|
2016-01-14 13:35:25 +01:00
|
|
|
* Paths = [{Path, Handler, Opts} | {Path, cowboy:fields(), Handler, HandlerOpts}]
|
2014-07-06 13:10:35 +02:00
|
|
|
* Handler = module()
|
2016-01-14 13:35:25 +01:00
|
|
|
* HandlerOpts = any()
|
2014-07-06 13:10:35 +02:00
|
|
|
|
|
|
|
Human readable list of routes mapping hosts and paths to handlers.
|
|
|
|
|
|
|
|
The syntax for routes is defined in the user guide.
|
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
=== tokens() = [binary()]
|
2014-07-06 13:10:35 +02:00
|
|
|
|
|
|
|
List of host_info and path_info tokens found during routing.
|
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
== Exports
|
2014-07-06 13:10:35 +02:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
=== compile(routes()) -> dispatch_rules()
|
2014-07-06 13:10:35 +02:00
|
|
|
|
|
|
|
Compile the routes for use by Cowboy.
|