Module sr_single_entity_handler

Base GET|PUT|DELETE /[entity]s/:id implementation.

Description

Base GET|PUT|DELETE /[entity]s/:id implementation

Data Types

options()

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

state()

state() = #{opts => options(), id => binary(), entity => sumo:user_doc(), module => module(), term() => term()}

Function Index

delete_resource/2Deletes the found entity.
handle_get/2Renders the found entity.
handle_patch/2Updates the found entity.
handle_put/2Updates the entity if found, otherwise it creates a new one.
resource_exists/2Verifies if there is an entity with the given id.
rest_init/2Announces the Req and moves on.

Function Details

delete_resource/2

delete_resource(Req::cowboy_req:req(), State::state()) -> {boolean() | halt, cowboy_req:req(), state()}

Deletes the found entity.

See also: resource_exists/2.

handle_get/2

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

Renders the found entity.

See also: resource_exists/2.

handle_patch/2

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

Updates the found entity. To parse the body, it uses update/2 from the model provided in the options.

See also: resource_exists/2.

handle_put/2

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

Updates the entity if found, otherwise it creates a new one. To parse the body, it uses either update/2 or from_json/2 (if defined) or from_json/1 from the model provided in the options.

See also: resource_exists/2.

resource_exists/2

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

Verifies if there is an entity with the given id. The provided id must be the value for the id field in SumoDb. If the entity is found, it's kept in the state.

See also: cowboy_rest:resource_exists/2, sumo:find/2.

rest_init/2

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

Announces the Req and moves on. It extracts the :id binding from the Req and leaves it in the id key in the state.

See also: cowboy_rest:rest_init/2.


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