Module sr_entities_handler

Base GET|POST /[entities] implementation.

Description

Base GET|POST /[entities] implementation

Data Types

options()

options() = #{path => string(), model => atom(), verbose => boolean()}

state()

state() = #{opts => options(), module => module(), term() => term()}

Function Index

allowed_methods/2Retrieves the list of allowed methods from Trails metadata.
announce_req/2Announces the Req.
content_types_accepted/2Always returns "application/json *" with handle_post.
content_types_provided/2Always returns "application/json" with handle_get.
handle_get/2Returns the list of all entities.
handle_post/2Creates a new entity.
handle_post/3Persists a new entity.
init/3Upgrades to cowboy_rest.
resource_exists/2Returns false for POST, true otherwise.
rest_init/2Announces the Req and moves on.

Function Details

allowed_methods/2

allowed_methods(Req::cowboy_req:req(), State::state()) -> {[binary()], cowboy_req:req(), state()}

Retrieves the list of allowed methods from Trails metadata. Parses the metadata associated with this path and returns the corresponding list of endpoints.

See also: cowboy_rest:allowed_methods/2.

announce_req/2

announce_req(Req::cowboy_req:req(), Opts::options()) -> cowboy_req:req()

Announces the Req. If verbose := true in Opts for this handler prints out a line indicating that endpoint that was hit.

See also: cowboy_rest:rest_init/2.

content_types_accepted/2

content_types_accepted(Req::cowboy_req:req(), State::state()) -> {[{{binary(), binary(), '*'}, atom()}], cowboy_req:req(), state()}

Always returns "application/json *" with handle_post.

See also: cowboy_rest:content_types_accepted/2.

To do

content_types_provided/2

content_types_provided(Req::cowboy_req:req(), State::state()) -> {[{binary(), atom()}], cowboy_req:req(), state()}

Always returns "application/json" with handle_get.

See also: cowboy_rest:content_types_provided/2.

To do

handle_get/2

handle_get(Req::cowboy_req:req(), State::state()) -> {iodata(), cowboy_req:req(), state()}

Returns the list of all entities. Fetches the entities from SumoDB using the model provided in the options.

To do

handle_post/2

handle_post(Req::cowboy_req:req(), State::state()) -> {{true, binary()} | false | halt, cowboy_req:req(), state()}

Creates a new entity. To parse the body, it uses from_json/2 from the model provided in the options.

handle_post/3

handle_post(Entity::sumo:user_doc(), Req1::cowboy_req:req(), State::state()) -> {{true, binary()}, cowboy_req:req(), state()}

Persists a new entity. The body must have been parsed beforehand.

init/3

init(Transport::{atom(), atom()}, Req::cowboy_req:req(), Opts::options()) -> {upgrade, protocol, cowboy_rest}

Upgrades to cowboy_rest. Basically, just returns {upgrade, protocol, cowboy_rest}

See also: cowboy_rest:init/3.

resource_exists/2

resource_exists(Req::cowboy_req:req(), State::state()) -> {boolean(), cowboy_req:req(), state()}

Returns false for POST, true otherwise.

See also: cowboy_rest:resource_exists/2.

rest_init/2

rest_init(Req::cowboy_req:req(), Opts::options()) -> {ok, cowboy_req:req(), state()}

Announces the Req and moves on. If verbose := true in Opts for this handler prints out a line indicating that endpoint that was hit.

See also: cowboy_rest:rest_init/2.


Generated by EDoc, Sep 14 2016, 05:42:50.