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

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


Loic, my idea about routing is that router is a piece of software that
translates input http request into presentation, convenient for handler and
selects proper handler for this with proper arguments.

I don't understand your logic: you allow to run regexp to validate if
constraint is a digit:   "/users/:user_id", [{user_id,fun() -> .. end}],
but you are strongly against validating method in constraints.

You tell me to spread logic between your router and my router. You tell me
that I need to use two routers that will somehow interfere with each other.
What is the idea? I really don't understand.


On Wed, Feb 13, 2013 at 2:39 PM, Loïc Hoguin <essen@REDACTED> wrote:

> On 02/13/2013 11:34 AM, Max Lapshin wrote:
>
>> 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.
>>
>
> Then in your init function do something like your_lib:route_method(Req)
> which returns {ok, Req, Action} if it's good or {shutdown, ...} if not?
> It'll do exactly what you just said.
>
>
> --
> Loïc Hoguin
> Erlang Cowboy
> Nine Nines
> http://ninenines.eu
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130213/14110c45/attachment.htm>


More information about the erlang-questions mailing list