[erlang-questions] Cowboy REST POST and custom status code

Max Grigoriev darkit@REDACTED
Wed Jun 12 08:08:47 CEST 2013


201 is just an example. We have legacy system with different components and 
I'm trying to change one of them to erlang.
And what I really need to set different status codes and what I see it's 
impossible without cowboy code changes :(

On Wednesday, June 12, 2013 7:26:25 AM UTC+3, Loïc Hoguin wrote:
>
> Cowboy will set the status code automatically. 
>
> POST requests will do a 201 if the resource didn't exist before and if a 
> URL to the resource is provided (201 requires a Location header): 
>
> make_post(Req, State) -> 
>      {{true, URL}, Req, State}. 
>
> If the resource did exist before and you return the above, a 303 will be 
> used. 
>
> If you only return true, Cowboy will do a 200 or 204 depending on 
> whether a response body has been set. 
>
> On 06/11/2013 08:17 PM, Max Grigoriev wrote: 
> > How can I set status code in my REST POST handler. 
> > 
> > Now I'm doing this 
> > 
> > |make_post(Req, State) -> 
> >    lager:info("post"), 
> >    Resp = cowboy_req:set_resp_body(<<"HELLO POST\n">>, Req), 
> >    {ok, Resp3} = cowboy_req:reply(201, Resp), 
> >    {true, Resp3, State}. 
> > | 
> > 
> > But I receive such errors: 
> > 
> > 1:43:10.510 [info] [nonode@REDACTED#pbshare_logic_registration#<0.205.0>] 
> > [handle_info#35] :Exit Logic from <0.204.0> Reason: 
> > 
> {function_clause,[{cowboy_req,reply,[204,[],<<>>,{http_req,#Port<0.6355>,ranch_tcp,keepalive,<0.204.0>,<<"POST">>,'HTTP/1.1',{{127,0,0,1},50024},<<"localhost">>,undefined,8080,<<"/rest/registration/make">>,[<<"make">>],<<>>,undefined,[],[{<<"user-agent">>,<<"curl/7.29.0">>},{<<"host">>,<<"localhost:8080">>},{<<"accept">>,<<"///">>},{<<"content-type">>,<<"application/json">>},{<<"content-length">>,<<"14">>}],[{<<"content-length">>,14},{<<"expect">>,undefined},{<<"content-length">>,14},{<<"content-type">>,{<<"application">>,<<"json">>,[]}},{<<"if-modified-since">>,undefined},{<<"if-none-match">>,undefined},{<<"if-unmodified-since">>,undefined},{<<"if-match">>,undefined},{<<"accept">>,[{{<<"/">>,<<"/">>,[]},1000,[]}]}],undefined,[{charset,undefined},{media_type,{<<"application">>,<<"json">>,[]}}],done,undefined,<<>>,false,done,[],<<>>,undefined}],[{file,"src/cowboy_req.erl"},{line,948}]},{cowboy_rest,respond,3,[{file,"src/cowboy_rest.erl"},{line,1085}]},{cowboy_rest,upgrade,4,[{file,"s 
>
> rc/cowboy_rest.erl"},{line,75}]},{cowboy_protocol,execute,4,[{file,"src/cowboy_protocol.erl"},{line,523}]}]} 
>
> > 21:43:10.510 [error] [Undefined#Undefined#emulator] 
> > [Undefined#Undefined] :Error in process <0.204.0> with exit value: 
> > {function_clause,[{cowboy_req,reply,[204,[],<<0 
> > bytes>>,{http_req,#Port<0.6355>,ranch_tcp,keepalive,<0.204.0>,<<4 
> > bytes>>,'HTTP/1.1',{{127,0,0,1},50024},<<9 bytes>>,undefined,8080,<<23 
> > bytes>>,[<<4 bytes>>],<<0 bytes>>,undefined,[],[{<<10 bytes>>,<<11 
> > bytes>>},{<<4 bytes>>,<<14 bytes>>},{<<6 bytes>>,<<3 bytes>>},{<<12 
> > bytes>>,<<16 bytes>>},{<<14 bytes>>,<<2 bytes>>}],[{<<14 
> > bytes>>,14},{<<6 bytes>>,undefined},{<<14 bytes>>,14},{<<12 
> > bytes>>,{<<11 bytes>>,<<4 bytes>>,[]}},{<<17 bytes>>,undefined},{<<13 
> > bytes>>,undefined},{<<19 bytes>>,undefined},{<<8 bytes>>,undefined... 
> > 
> > 
> > 
> > _______________________________________________ 
> > erlang-questions mailing list 
> > erlang-q...@REDACTED <javascript:> 
> > http://erlang.org/mailman/listinfo/erlang-questions 
> > 
>
>
> -- 
> Loïc Hoguin 
> Erlang Cowboy 
> Nine Nines 
> http://ninenines.eu 
> _______________________________________________ 
> erlang-questions mailing list 
> erlang-q...@REDACTED <javascript:> 
> http://erlang.org/mailman/listinfo/erlang-questions 
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130611/3af29b32/attachment.htm>


More information about the erlang-questions mailing list