[erlang-questions] Cowboy routes with Method as a condition

Max Lapshin max.lapshin@REDACTED
Wed Feb 13 11:34:31 CET 2013

handle(Req, State) ->
    handle_method(cowboy_req:get(method, Req), Req, State).  will require

handle_method(<<"GET">>, Req, State)
handle_method(<<"DELETE">>, Req, State)
handle_method(Other, Req, State)
  here we copy from module to module default reply on "method not
supported" or 404, whatever we choose.

with method constraints code can look so:

init(_, Req, [Action]) ->
 {ok, Req, Action}.

handle(Req, show) ->

handle(Req, destroy) ->

handle(Req, list) ->

And no "default handler" because it is not required. Only good requests can
pass to this handler.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130213/08fd3923/attachment.htm>

More information about the erlang-questions mailing list