<div dir="ltr">Max, one could insert a middleware before cowboy_router which mangle URI to be Method/URI and then in the router rules treat Method chunk as binding -- hence, method constraints.<div class="gmail_extra"><br>

--Vladimir<br><br><div class="gmail_quote">On Wed, Feb 13, 2013 at 3:02 PM, Loïc Hoguin <span dir="ltr"><<a href="mailto:essen@ninenines.eu" target="_blank">essen@ninenines.eu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

The HTTP RFC says this on page 6:<br>
<br>
   It builds on the discipline of reference<br>
   provided by the Uniform Resource Identifier (URI) [3], as a location<br>
   (URL) [4] or name (URN) [20], for indicating the resource to which a<br>
   method is to be applied.<br>
<br>
It then defines resources as follow on page 9:<br>
<br>
      A network data object or service that can be identified by a URI,<br>
      as defined in section 3.2. Resources may be available in multiple<br>
      representations (e.g. multiple languages, data formats, size, and<br>
      resolutions) or vary in other ways.<br>
<br>
It then describes how to locate resources in many of the following sections, starting with section 3.2 page 18.<br>
<br>
Cowboy implements this. It maps URIs to resources. It makes absolutely no assumptions as to how your resources operate. Anything that is part of the URI can and will be used to locate resources. But if it's not part of the URI, then it's not something used to find resources as defined by the HTTP standard, which makes it out of the scope of the project.<br>


<br>
It still provides you with many ways to plug yourself into Cowboy to achieve what you want, which include:<br>
<br>
 *  Middleware<br>
 *  Protocol upgrade (what REST handlers are doing)<br>
 *  init/3 based method dispatching<br>
 *  handle/2 based method dispatching<br>
<br>
And I'm sure there's more.<div class="im"><br>
<br>
On 02/13/2013 11:42 AM, Max Lapshin wrote:<br>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
Loic, my idea about routing is that router is a piece of software that<br>
translates input http request into presentation, convenient for handler<br>
and selects proper handler for this with proper arguments.<br>
<br>
I don't understand your logic: you allow to run regexp to validate if<br>
constraint is a digit:   "/users/:user_id", [{user_id,fun() -> .. end}],<br>
but you are strongly against validating method in constraints.<br>
<br>
You tell me to spread logic between your router and my router. You tell<br>
me that I need to use two routers that will somehow interfere with each<br>
other. What is the idea? I really don't understand.<br>
<br>
<br>
On Wed, Feb 13, 2013 at 2:39 PM, Loïc Hoguin <<a href="mailto:essen@ninenines.eu" target="_blank">essen@ninenines.eu</a><br></div><div class="im">
<mailto:<a href="mailto:essen@ninenines.eu" target="_blank">essen@ninenines.eu</a>>> wrote:<br>
<br>
    On 02/13/2013 11:34 AM, Max Lapshin wrote:<br>
<br>
        handle(Req, State) -><br></div>
              handle_method(cowboy_req:get(_<u></u>_method, Req), Req, State).<div><div class="h5"><br>
          will require<br>
<br>
<br>
        handle_method(<<"GET">>, Req, State)<br>
        handle_method(<<"DELETE">>, Req, State)<br>
        handle_method(Other, Req, State)<br>
            here we copy from module to module default reply on "method not<br>
        supported" or 404, whatever we choose.<br>
<br>
<br>
        with method constraints code can look so:<br>
<br>
<br>
        init(_, Req, [Action]) -><br>
           {ok, Req, Action}.<br>
<br>
<br>
        handle(Req, show) -><br>
            ..<br>
<br>
        handle(Req, destroy) -><br>
            ..<br>
<br>
        handle(Req, list) -><br>
            ..<br>
            .<br>
<br>
        And no "default handler" because it is not required. Only good<br>
        requests<br>
        can pass to this handler.<br>
<br>
<br>
    Then in your init function do something like<br>
    your_lib:route_method(Req) which returns {ok, Req, Action} if it's<br>
    good or {shutdown, ...} if not? It'll do exactly what you just said.<br>
<br>
<br>
    --<br>
    Loïc Hoguin<br>
    Erlang Cowboy<br>
    Nine Nines<br>
    <a href="http://ninenines.eu" target="_blank">http://ninenines.eu</a><br>
<br>
<br>
</div></div></blockquote><div class="HOEnZb"><div class="h5">
<br>
<br>
-- <br>
Loïc Hoguin<br>
Erlang Cowboy<br>
Nine Nines<br>
<a href="http://ninenines.eu" target="_blank">http://ninenines.eu</a><br></div></div><div class="HOEnZb"><div class="h5">
______________________________<u></u>_________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/<u></u>listinfo/erlang-questions</a><br>
</div></div></blockquote></div><br></div></div>