cowboy_router:compile(3)

NAME

cowboy_router:compile - Compile routes to the resources

DESCRIPTION
    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
    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

cowboy_router(3)