aboutsummaryrefslogtreecommitdiffstats
path: root/doc/src/manual/cowboy_router.compile.asciidoc
blob: f0b3f14e09de32fff96972ddbada4ae4c6185e6a (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
= cowboy_router:compile(3)

== Name

cowboy_router:compile - Compile routes to the resources

== Description

[source,erlang]
----
compile(cowboy_router:routes()) -> cowboy_router:dispatch_rules()
----

Compile routes to the resources.

Takes a human readable list of routes and transforms it
into a form more efficient to process.

== Arguments

Routes::

Human readable list of routes.

== Return value

An opaque dispatch rules value is returned. This value
must be given to Cowboy as a middleware environment value.

== Changelog

* *1.0*: Function introduced.

== Examples

.Compile routes and start a listener
[source,erlang]
----
Dispatch = cowboy_router:compile([
    {'_', [
        {"/", toppage_h, []},
        {"/[...], cowboy_static, {priv_dir, my_example_app, ""}}
    ]}
]),

{ok, _} = cowboy:start_clear(example, [{port, 8080}], #{
    env => #{dispatch => Dispatch}
}).
----

== See also

link:man:cowboy_router(3)[cowboy_router(3)]