[99s-extend] question to rest handler

Witali Monastyrjow chatlano at googlemail.com
Fri May 17 17:41:11 CEST 2013


Hi all,

I am learning cowboy by building a small application with rest interface.
I have a hello_world rest handler and I want to implement POST method that
returns
json as response to a client. Therefor I implemented  callbacks
allowed_methods,
content_types_accepted and hello_json. The docu says user callbacks can
return {Value, Req, State} and also can return {halt, Req, State}. It is
not really clear
what that Value should be. So I tried {ok, Req, State} and {true, Req,
State} and with
both values I have

=ERROR REPORT==== 11-May-2013::16:06:40 ===
Error in process <0.6649.0> with exit value:
{function_clause,[{cowboy_req,reply,[303,....

and client gets right response. If I use {halt, Req, State} the client gets
right response too
and there is no errors. So, Is it right way to write a POST callback and
what Values can
be used for user callbacks? I write my code below.

amike,
Vitali

allowed_methods(Req, State) ->
{[<<"POST">>, <<"DELETE">>], Req, State}.

content_types_accepted(Req, State) ->
{[
    {{<<"application">>, <<"x-www-form-urlencoded">>, []}, hello_json}
 ], Req, State}.

hello_json(Req, State) ->
{ok, Req2} = cowboy_req:reply(200, [{<<"content-type">>,
<<"application/json">>} ], <<"{\"rest\": \"Hello World!\"}">>, Req),
{halt, Req2, State}.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ninenines.eu/archives/extend/attachments/20130517/629071b8/attachment.html>


More information about the Extend mailing list