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

Max Lapshin max.lapshin@REDACTED
Wed Feb 13 11:29:54 CET 2013

I can give you an example:

URL  /users/15

GET /users/15  should be routed to function that shows user
DELETE /users/15  should be route to function that destroys user

Currently you are forcing user to spread routing among different places:

"/users/:user_id", user_handler, []  and there, in init I need to check if
this method is GET or DELETE or anything else

but with method constraints, it will work as following:

"/users/:user_id", [{method,<<"GET">>}], user_handler, [show]
"/users/:user_id", [{method,<<"DELETE">>}], user_handler, [destroy]

I don't see any HTTP pure theory violation in it. It looks rather
convenient and more clear than checking which method was passed by user.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130213/6c455290/attachment.htm>

More information about the erlang-questions mailing list