Debian Codegraph @

test/handlers/create_resource_h.erl

raw
1 -module(create_resource_h).
2
3 -export([init/2]).
4 -export([allowed_methods/2]).
5 -export([resource_exists/2]).
6 -export([content_types_accepted/2]).
7 -export([from_text/2]).
8
9 init(Req, Opts) ->
10 {cowboy_rest, Req, Opts}.
11
12 allowed_methods(Req, State) ->
13 {[<<"POST">>], Req, State}.
14
15 resource_exists(Req, State) ->
16 {true, Req, State}.
17
18 content_types_accepted(Req, State) ->
19 {[{{<<"application">>, <<"text">>, []}, from_text}], Req, State}.
20
21 from_text(Req=#{qs := Qs}, State) ->
22 NewURI = [cowboy_req:uri(Req), "/foo"],
23 case Qs of
24 <<"created">> ->
25 {{created, NewURI}, Req, State};
26 <<"see_other">> ->
27 {{see_other, NewURI}, Req, State}
28 end.