Module trails

Trails main interface.

Description

Trails main interface. Use the functions provided in this module to inteact with trails.

Data Types

metadata()

metadata(X) = #{method() => X}

method()

method() = get | put | post | delete | patch | head | options

route_match()

route_match() = '_' | iodata()

route_path()

route_path() = {Path::route_match(), Handler::module(), Opts::any()} | {Path::route_match(), cowboy:fields(), Handler::module(), Opts::any()}

trail()

abstract datatype: trail()

trails()

trails() = [trail() | route_path()]

Function Index

all/0Retrieves all stored trails.
all/1Retrieves all stored trails for the given HostMatch
all/2Retrieves all stored trails for the given Server and HostMatch
api_root/0Get api_root env param value if any, empty otherwise.
api_root/1Set api_root env param to the given Path.
compile/1Compiles the given list of trails routes, also compatible with cowboy routes.
constraints/1Gets the constraints from the given trail.
handler/1Gets the handler from the given trail.
host_matches/1
metadata/1Gets the metadata from the given trail.
options/1Gets the options from the given trail.
path_match/1Gets the path_match from the given trail.
retrieve/1Fetch the trail that matches with the given path.
retrieve/2Fetch the trail that matches with the given host and path.
retrieve/3Fetch the trail that matches with the given server and host and path.
servers/0
single_host_compile/1Equivalent to compile([{'_', Trails}]).
store/1Store the given list of trails.
store/2
trail/2Equivalent to trail(PathMatch, ModuleHandler, [], #{}, []).
trail/3Equivalent to trail(PathMatch, ModuleHandler, Options, #{}, []).
trail/4Equivalent to trail(PathMatch, ModuleHandler, Options, MetaData, []).
trail/5This function allows you to add additional information to the cowboy handler, such as: resource path, handler module, options and metadata.
trails/1This function allows you to define the routes on each resource handler, instead of defining them all in one place (as you're required to do with cowboy).

Function Details

all/0

all() -> [trail()]

Retrieves all stored trails.

all/1

all(HostMatch::route_match()) -> [trail()]

Retrieves all stored trails for the given HostMatch

all/2

all(Server::ranch:ref(), HostMatch::route_match()) -> [trail()]

Retrieves all stored trails for the given Server and HostMatch

api_root/0

api_root() -> string()

Get api_root env param value if any, empty otherwise.

api_root/1

api_root(Path::string()) -> ok

Set api_root env param to the given Path.

compile/1

compile(Routes::[{Host::route_match(), Trails::trails()}]) -> cowboy_router:dispatch_rules()

Compiles the given list of trails routes, also compatible with cowboy routes.

constraints/1

constraints(Trail::trail()) -> cowboy:fields()

Gets the constraints from the given trail.

handler/1

handler(Trail::trail()) -> module()

Gets the handler from the given trail.

host_matches/1

host_matches(ServerRef::ranch:ref()) -> [route_match()]

metadata/1

metadata(Trail::trail()) -> #{}

Gets the metadata from the given trail.

options/1

options(Trail::trail()) -> any()

Gets the options from the given trail.

path_match/1

path_match(Trail::trail()) -> route_match()

Gets the path_match from the given trail.

retrieve/1

retrieve(PathMatch::string()) -> trail() | notfound

Fetch the trail that matches with the given path.

retrieve/2

retrieve(HostMatch::route_match(), PathMatch::string()) -> trail() | notfound

Fetch the trail that matches with the given host and path.

retrieve/3

retrieve(Server::ranch:ref(), HostMatch::route_match(), PathMatch::string()) -> trail() | notfound

Fetch the trail that matches with the given server and host and path.

servers/0

servers() -> [ranch:ref()]

single_host_compile/1

single_host_compile(Trails::trails()) -> cowboy_router:dispatch_rules()

Equivalent to compile([{'_', Trails}]).

store/1

store(Trails::trails() | [{HostMatch::route_match(), Trails::trails()}]) -> ok

Store the given list of trails.

store/2

store(Server::ranch:ref(), Trails::trails() | [{HostMatch::route_match(), Trails::trails()}]) -> ok

trail/2

trail(PathMatch::route_match(), ModuleHandler::module()) -> trail()

Equivalent to trail(PathMatch, ModuleHandler, [], #{}, []).

trail/3

trail(PathMatch::route_match(), ModuleHandler::module(), Options::any()) -> trail()

Equivalent to trail(PathMatch, ModuleHandler, Options, #{}, []).

trail/4

trail(PathMatch::route_match(), ModuleHandler::module(), Options::any(), MetaData::#{}) -> trail()

Equivalent to trail(PathMatch, ModuleHandler, Options, MetaData, []).

trail/5

trail(PathMatch::route_match(), ModuleHandler::module(), Options::any(), MetaData::#{}, Constraints::cowboy:fields()) -> trail()

This function allows you to add additional information to the cowboy handler, such as: resource path, handler module, options and metadata. Normally used to document handlers.

trails/1

trails(Handlers::module() | [module()]) -> trails()

This function allows you to define the routes on each resource handler, instead of defining them all in one place (as you're required to do with cowboy). Your handler must implement the callback trails/0 and return the specific routes for that handler. That callback is invoked for each given module and then the results are concatenated.


Generated by EDoc