[erlang-questions] trying to learn cowboy

Loïc Hoguin essen@REDACTED
Sun Jun 28 21:07:55 CEST 2015



On 06/28/2015 08:55 PM, Ben Hsu wrote:
> Hello Erlangers
>
> I am going through some basic steps learning cowboy, and I'm doing
> something wrong, but I can't figure it out.
>
> In the code below, I'm pattern matching against cowboy_req:method(Req),
> and it _should_ be returning {'GET', _}, which takes me to the first
> branch of the case statement. But it keeps executing the default case.
>
> I printed out what cowboy_req:method is returning, and it looks like
> GET, In the spirit of shotgun-debugging this I've tried matching against
> 'GET', "GET", <<'GET'>>, and <<"GET">>, none of which work
>
> I'm sure there is something simple I am missing here. What is it?
>
>
> Thank you for your time and patience :)
>
> handle(Req, State) ->
>      Reply = case cowboy_req:method(Req) of
>          {'GET', _} ->

{<<"GET">>, _}

Not sure where you saw any 'GET'. :-)

> % this is never executed when I do a curl-GET against my app
> SomeMsg = "some message",
> {ok, Req2} = cowboy_req:reply(200,
> [{<<"content-type">>, <<"text/plain">>}],
> SomeMsg,
> Req),
>   {ok, Req2, State};
>          _ ->
> % even though i am printing out what cowboy_req:method returns here and
> it says GET
> {FNORD, _} = cowboy_req:method(Req),
>              {ok, R} = cowboy_req:reply(200, [], FNORD, Req),
>              R
>      end,
>      {ok, Reply, State}.
>
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>

-- 
Loïc Hoguin
http://ninenines.eu
Author of The Erlanger Playbook,
A book about software development using Erlang



More information about the erlang-questions mailing list