201 is just an example. We have legacy system with different components and I'm trying to change one of them to erlang.<div>And what I really need to set different status codes and what I see it's impossible without cowboy code changes :(<br><br>On Wednesday, June 12, 2013 7:26:25 AM UTC+3, Loïc Hoguin wrote:<blockquote class="gmail_quote" style="margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">Cowboy will set the status code automatically.
<br>
<br>POST requests will do a 201 if the resource didn't exist before and if a
<br>URL to the resource is provided (201 requires a Location header):
<br>
<br>make_post(Req, State) ->
<br> {{true, URL}, Req, State}.
<br>
<br>If the resource did exist before and you return the above, a 303 will be
<br>used.
<br>
<br>If you only return true, Cowboy will do a 200 or 204 depending on
<br>whether a response body has been set.
<br>
<br>On 06/11/2013 08:17 PM, Max Grigoriev wrote:
<br>> How can I set status code in my REST POST handler.
<br>>
<br>> Now I'm doing this
<br>>
<br>> |make_post(Req, State) ->
<br>> lager:info("post"),
<br>> Resp = cowboy_req:set_resp_body(<<"<wbr>HELLO POST\n">>, Req),
<br>> {ok, Resp3} = cowboy_req:reply(201, Resp),
<br>> {true, Resp3, State}.
<br>> |
<br>>
<br>> But I receive such errors:
<br>>
<br>> 1:43:10.510 [info] [nonode@nohost#pbshare_logic_<wbr>registration#<0.205.0>]
<br>> [handle_info#35] :Exit Logic from <0.204.0> Reason:
<br>> {function_clause,[{cowboy_req,<wbr>reply,[204,[],<<>>,{http_req,#<wbr>Port<0.6355>,ranch_tcp,<wbr>keepalive,<0.204.0>,<<"POST">><wbr>,'HTTP/1.1',{{127,0,0,1},<wbr>50024},<<"localhost">>,<wbr>undefined,8080,<<"/rest/<wbr>registration/make">>,[<<"make"<wbr>>>],<<>>,undefined,[],[{<<"<wbr>user-agent">>,<<"curl/7.29.0"><wbr>>},{<<"host">>,<<"localhost:<wbr>8080">>},{<<"accept">>,<<"///"<wbr>>>},{<<"content-type">>,<<"<wbr>application/json">>},{<<"<wbr>content-length">>,<<"14">>}],[<wbr>{<<"content-length">>,14},{<<"<wbr>expect">>,undefined},{<<"<wbr>content-length">>,14},{<<"<wbr>content-type">>,{<<"<wbr>application">>,<<"json">>,[]}}<wbr>,{<<"if-modified-since">>,<wbr>undefined},{<<"if-none-match"><wbr>>,undefined},{<<"if-<wbr>unmodified-since">>,undefined}<wbr>,{<<"if-match">>,undefined},{<<wbr><"accept">>,[{{<<"/">>,<<"/">><wbr>,[]},1000,[]}]}],undefined,[{<wbr>charset,undefined},{media_<wbr>type,{<<"application">>,<<"<wbr>json">>,[]}}],done,undefined,<<wbr><>>,false,done,[],<<>>,<wbr>undefined}],[{file,"src/<wbr>cowboy_req.erl"},{line,948}]},<wbr>{cowboy_rest,respond,3,[{file,<wbr>"src/cowboy_rest.erl"},{line,<wbr>1085}]},{cowboy_rest,upgrade,<wbr>4,[{file,"s
<br>rc/cowboy_rest.erl"},{line,75}<wbr>]},{cowboy_protocol,execute,4,<wbr>[{file,"src/cowboy_protocol.<wbr>erl"},{line,523}]}]}
<br>> 21:43:10.510 [error] [Undefined#Undefined#emulator]
<br>> [Undefined#Undefined] :Error in process <0.204.0> with exit value:
<br>> {function_clause,[{cowboy_req,<wbr>reply,[204,[],<<0
<br>> bytes>>,{http_req,#Port<0.<wbr>6355>,ranch_tcp,keepalive,<0.<wbr>204.0>,<<4
<br>> bytes>>,'HTTP/1.1',{{127,0,0,<wbr>1},50024},<<9 bytes>>,undefined,8080,<<23
<br>> bytes>>,[<<4 bytes>>],<<0 bytes>>,undefined,[],[{<<10 bytes>>,<<11
<br>> bytes>>},{<<4 bytes>>,<<14 bytes>>},{<<6 bytes>>,<<3 bytes>>},{<<12
<br>> bytes>>,<<16 bytes>>},{<<14 bytes>>,<<2 bytes>>}],[{<<14
<br>> bytes>>,14},{<<6 bytes>>,undefined},{<<14 bytes>>,14},{<<12
<br>> bytes>>,{<<11 bytes>>,<<4 bytes>>,[]}},{<<17 bytes>>,undefined},{<<13
<br>> bytes>>,undefined},{<<19 bytes>>,undefined},{<<8 bytes>>,undefined...
<br>>
<br>>
<br>>
<br>> ______________________________<wbr>_________________
<br>> erlang-questions mailing list
<br>> <a href="javascript:" target="_blank" gdf-obfuscated-mailto="rN1__NSa_GsJ">erlang-q...@erlang.org</a>
<br>> <a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/<wbr>listinfo/erlang-questions</a>
<br>>
<br>
<br>
<br>--
<br>Loïc Hoguin
<br>Erlang Cowboy
<br>Nine Nines
<br><a href="http://ninenines.eu" target="_blank">http://ninenines.eu</a>
<br>______________________________<wbr>_________________
<br>erlang-questions mailing list
<br><a href="javascript:" target="_blank" gdf-obfuscated-mailto="rN1__NSa_GsJ">erlang-q...@erlang.org</a>
<br><a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/<wbr>listinfo/erlang-questions</a>
<br></blockquote></div>