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

Loïc Hoguin essen@REDACTED
Wed Feb 13 10:27:48 CET 2013

Rails is a framework, Cowboy is trying hard not to be.

HTTP has a long section about mapping URIs to resources on which you 
perform actions. Actions are identified by methods, but aren't used to 
find the resource to be used. Cowboy simply follows HTTP.

Adding ways to use methods to map to handlers or functions directly into 
Cowboy would just break this concept of resources that Cowboy is trying 
hard to protect.

It shouldn't be difficult to write a middleware that allows you to do 
this efficiently if that's what you want, or fork the current router to 
add the functionality, but that's something that won't land in Cowboy 

On 02/13/2013 10:05 AM, Max Lapshin wrote:
> I understand it.
> But look at rails routing: you can add constraints not only on bindings,
> but also on methods. It is very convenient, because it allows CRUD
> routing from routes and it makes code smaller due to removing protection
> of GET method.
> If I add route:
> "/items/:item/destroy", item_handler, [destroy]
> than I need to check if this method is POST, because it is a very bad
> idea to make any destructive action on GET.
> If I add:
> "items/:item/destroy", [{method,<<"POST">>}], item_handler, [destroy]
> I don't need to write useless code.
> Why are you against it?
> Let's use not  'method', but <<"method">> or any other name that will
> not clash with bindings.

Loïc Hoguin
Erlang Cowboy
Nine Nines

More information about the erlang-questions mailing list