erf_router (erf v0.2.0)

View Source

Summary

Functions

Generates an Erlang Syntax Tree of a router module from an API AST.

Handles an HTTP request.

Loads a router module into the Erlang Runtime System.

Types

callback/0

-type callback() :: module().

callback_spec/0

-type callback_spec() :: callback() | #{erf:path() => callback()}.

generator_opts/0

-type generator_opts() :: #{callback := callback_spec(), static_routes := [erf:static_route()]}.

t/0

-type t() :: erl_syntax:syntaxTree().

Functions

generate(API, Opts)

-spec generate(API, Opts) -> Result
                  when
                      API :: erf:api(),
                      Opts :: generator_opts(),
                      Result :: {Mod, Router},
                      Mod :: module(),
                      Router :: t().

Generates an Erlang Syntax Tree of a router module from an API AST.

handle(Name, Request)

-spec handle(Name, Request) -> Result
                when Name :: atom(), Request :: erf:request(), Result :: erf:response().

Handles an HTTP request.

load(Router)

-spec load(Router) -> Result
              when
                  Router :: t(),
                  Result :: ok | {ok, Warnings} | error | {error, {Errors, Warnings}},
                  Errors :: [term()],
                  Warnings :: [term()].

Loads a router module into the Erlang Runtime System.