View Source erf (erf v0.1.2)

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

Summary

Functions

Returns the router for an instance of the server.
Reloads the configuration for an instance of the server.
Starts the supervision tree for an instance of the server.
Stops the supervision tree for an instance of the server.

Types

-type api() :: erf_parser:api().
-type body() :: undefined | njson:t().
-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(),
            min_acceptors => pos_integer(),
            accept_timeout => pos_integer(),
            request_timeout => pos_integer(),
            header_timeout => pos_integer(),
            body_timeout => pos_integer(),
            max_body_size => pos_integer(),
            log_level => logger:level()}.
-type header() :: {binary(), binary()}.
-type method() :: get | post | put | delete | patch | head | options | trace | connect.
-type path_parameter() :: {binary(), binary()}.
-type query_parameter() :: {binary(), binary()}.
-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(),
            context => any()}.
-type response() ::
          {StatusCode :: pos_integer(), Headers :: [header()], Body :: body() | {file, binary()}}.
-type static_dir() :: {dir, binary()}.
-type static_file() :: {file, binary()}.
-type static_route() :: {Path :: binary(), Resource :: static_file() | static_dir()}.

Functions

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