From c807880f7ac73f813b2660ea81a00f7712a4e793 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Mon, 29 Aug 2016 12:39:49 +0200 Subject: Add old mailing list archives --- _build/static/archives/extend/2013-May/000144.html | 120 +++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 _build/static/archives/extend/2013-May/000144.html (limited to '_build/static/archives/extend/2013-May/000144.html') diff --git a/_build/static/archives/extend/2013-May/000144.html b/_build/static/archives/extend/2013-May/000144.html new file mode 100644 index 00000000..bab09432 --- /dev/null +++ b/_build/static/archives/extend/2013-May/000144.html @@ -0,0 +1,120 @@ + + + + [99s-extend] question to rest handler + + + + + + + + + + +

[99s-extend] question to rest handler

+ Loïc Hoguin + essen at ninenines.eu +
+ Fri May 17 18:15:47 CEST 2013 +

+
+ +
All the callbacks are explained in 
+http://ninenines.eu/docs/en/cowboy/HEAD/manual/cowboy_rest
+
+In your case take a special look at content_types_accepted.
+
+On 05/17/2013 05:41 PM, Witali Monastyrjow wrote:
+> 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}.
+>
+>
+> _______________________________________________
+> Extend mailing list
+> Extend at lists.ninenines.eu
+> http://lists.ninenines.eu:81/listinfo/extend
+>
+
+
+-- 
+Loïc Hoguin
+Erlang Cowboy
+Nine Nines
+http://ninenines.eu
+
+
+ + +
+

+ +
+More information about the Extend +mailing list
+ -- cgit v1.2.3