aboutsummaryrefslogtreecommitdiffstats
path: root/doc/src/manual/cowboy_router.ezdoc
blob: 8d45e67da343e04771078174707f72af12b2c362 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
::: cowboy_router

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.

Environment input:

* dispatch = dispatch_rules()

Environment output:

* handler = module()
* handler_opts = any()

:: Types

: bindings() = [{atom(), binary()}]

List of bindings found during routing.

: dispatch_rules() - opaque to the user

Rules for dispatching request used by Cowboy.

: routes() = [{Host, Paths} | {Host, cowboy:fields(), Paths}]

Types:

* Host = Path = '_' | iodata()
* Paths = [{Path, Handler, Opts} | {Path, cowboy:fields(), Handler, Opts}]
* Handler = module()
* Opts = any()

Human readable list of routes mapping hosts and paths to handlers.

The syntax for routes is defined in the user guide.

: tokens() = [binary()]

List of host_info and path_info tokens found during routing.

:: Exports

: compile(Routes) -> Dispatch

Types:

* Routes = routes()
* Dispatch = dispatch_rules()

Compile the routes for use by Cowboy.