It’s not immediately obvious how to handle different HTTP methods using Cowboy.
This SO answer, and one of the examples show the way:
handle(Req, State) ->
{Method, Req2} = cowboy_req:method(Req),
{ok, Req3} = process_req(Method, Req2),
{ok, Req3, State}.
process_req(<<"POST">>, Req) ->
{ok, Body, Req2} = cowboy_req:body_qs(Req),
_Foo = proplists:get_value(<<"foo">>, Body),
cowboy_req:reply(200, [
{<<"content-type">>, <<"text/plain; charset=utf-8">>}
], <<"ohai">>, Req);
process_req(_, _, Req) ->
%% Method not allowed.
cowboy_req:reply(405, Req).
Neat solution!
I want to share another article which may be useful for your readers. It deals with handling websockets in an erlang app. Here it is: http://www.oxagile.com/company/blog/handling-websocket-connections-in-erlang-application/.
Hope you’ll find it helpful