erf (erf v0.1.2)

View Source
erf is a library that provides a design-first framework to build RESTful APIs in Erlang.

Summary

Types

api/0

-type api() :: erf_parser:api().

body/0

-type body() :: undefined | njson:t().

conf/0

-type conf() ::
          #{spec_path := binary(),
            callback := module(),
            port => inet:port_number(),
            name => atom(),
            spec_parser => module(),
            preprocess_middlewares => [module()],
            postprocess_middlewares => [module()],
            ssl => boolean(),
            certfile => binary(),
            keyfile => binary(),
            static_routes => [static_route()],
            swagger_ui => boolean(),
            log_level => logger:level()}.

header/0

-type header() :: {binary(), binary()}.

method/0

-type method() :: get | post | put | delete | patch | head | options | trace | connect.

path_parameter/0

-type path_parameter() :: {binary(), binary()}.

query_parameter/0

-type query_parameter() :: {binary(), binary()}.

request/0

-type request() ::
          #{scheme := undefined | binary(),
            host := undefined | binary(),
            port := undefined | 1..65535,
            path := [binary()],
            path_parameters => [path_parameter()],
            method := method(),
            query_parameters := [query_parameter()],
            headers := [header()],
            body := body(),
            peer := undefined | binary(),
            route := binary(),
            context => any()}.

response/0

-type response() ::
          {StatusCode :: pos_integer(), Headers :: [header()], Body :: body() | {file, binary()}}.

route_patterns/0

-type route_patterns() :: [{Route :: binary(), RouteRegEx :: re:mp()}].

static_dir/0

-type static_dir() :: {dir, binary()}.

static_file/0

-type static_file() :: {file, binary()}.

static_route/0

-type static_route() :: {Path :: binary(), Resource :: static_file() | static_dir()}.

Functions

get_router(Name)

-spec get_router(Name) -> Result
                    when
                        Name :: atom(),
                        Result :: {ok, Router} | {error, Reason},
                        Router :: binary(),
                        Reason :: term().
Returns the router for an instance of the server.

init(_)

match_route(Name, RawPath)

-spec match_route(Name, RawPath) -> Result
                     when
                         Name :: atom(),
                         RawPath :: binary(),
                         Result :: {ok, Route} | {error, Reason},
                         Route :: binary(),
                         Reason :: term().

reload_conf(Name, Conf)

-spec reload_conf(Name, Conf) -> Result
                     when
                         Name :: atom(),
                         Conf :: erf_conf:t(),
                         Result :: ok | {error, Reason},
                         Reason :: term().
Reloads the configuration for an instance of the server.

start_link(Conf)

-spec start_link(Conf) -> Result
                    when
                        Conf :: conf(),
                        Result :: {ok, Pid} | ignore | {error, Reason},
                        Pid :: pid(),
                        Reason :: term().
Starts the supervision tree for an instance of the server.

stop(Name)

-spec stop(Name) -> Result when Name :: atom(), Result :: ok | {error, Reason}, Reason :: term().
Stops the supervision tree for an instance of the server.