1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
<tt>
<span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">Hi all,�</span><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><br>
<br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">I am learning cowboy by building a small application with rest interface.�</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><br>
I have a hello_world rest handler and I want to implement POST method that returns �</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">json as response to a client. Therefor I implemented �callbacks allowed_methods,�</div><br>
<div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">content_types_accepted and hello_json. The docu says user callbacks can�</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><br>
return {Value, Req, State} and also can return {halt, Req, State}. It is not really clear�</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">what that Value should be. So I tried {ok, Req, State} and {true, Req, State} and with</div><br>
<div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">both values I have�</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><br>
<br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><div>=ERROR REPORT==== 11-May-2013::16:06:40 ===</div><div>Error in process <0.6649.0> with exit value: {function_clause,[{cowboy_req,reply,[303,....</div><br>
</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><br>
and client gets right response. If I use {halt, Req, State} the client gets right response too</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">and there is no errors. So, Is it right way to write a POST callback and what Values can</div><br>
<div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">be used for user callbacks? I write my code below.</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><br>
<br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">amike,�</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><br>
Vitali</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><br>
<div>allowed_methods(Req, State) -></div><div><span style="white-space:pre-wrap"> </span>{[<<"POST">>, <<"DELETE">>], Req, State}.</div><div><br></div><div>content_types_accepted(Req, State) -></div><br>
<div><span style="white-space:pre-wrap"> </span>{[</div><div><span style="white-space:pre-wrap"> </span>�� �{{<<"application">>, <<"x-www-form-urlencoded">>, []}, hello_json}</div><br>
<div><span style="white-space:pre-wrap"> </span>�],�Req, State}.</div><div><br></div><div>hello_json(Req, State) -></div><div><span style="white-space:pre-wrap"> </span>{ok, Req2} = cowboy_req:reply(200, [{<<"content-type">>, <<"application/json">>} ], <<"{\"rest\": \"Hello World!\"}">>, Req),</div><br>
<div><span style="white-space:pre-wrap"> </span>{halt, Req2, State}.</div></div><br>
</tt>
|