[erlang-questions] Getting started with Cowboy

AD <>
Tue Mar 20 14:09:03 CET 2012


I am fairly new to cowboy/erlang as well but found it very easy to use.
 You simply need to write your own handler module and then in your
handle(Req,State) callback you just do what you want with the request.

you can make a simple case statement to match on paths (look at
cowboy_http_req).  For example to check for a header I think you can do
something like

 case cowboy_http_req:header('Host',Req) of
     'www.domain.com' ->
       {ok, Req2} = cowboy_http_req:reply(200, [{'Content-Type',
<<"text/html">>}],<<"You went to www !">>,Req);
     'images.domain.com' ->
       {ok, Req2} = cowboy_http_req:reply(200, [{'Content-Type',
<<"text/html">>}],<<"You went to images">>,Req);
  end
  {ok, Req2, State}.

Pretty straightforward.

-AD

On Tue, Mar 20, 2012 at 6:42 AM, Loïc Hoguin <> wrote:

> People using the Cowboy REST handlers are currently using the Webmachine
> documentation to do it. It's based on the same diagram and the resource
> callbacks have the same names and mostly the same semantics.
>
> Proper documentation is in preparation.
>
>
> On 03/20/2012 03:54 AM, Art Beall wrote:
>
>> Hello,
>> First post here, thanks for all the information provided through this
>> digest!
>> At my company we're looking at implementing an api using a RESTfull web
>> service. Erlang has been suggested. I've been looking for some
>> documentation, examples or tutorials on using Cowboy. My background is
>> in Windows/C++. I've taught myself Erlang from the Programming Erlang
>> book. But the unix tools are mostly new to me.
>> Hoping I could get some help or suggestions for getting started.
>> Thanks for any help!
>> Art
>>
>>
>> ______________________________**_________________
>> erlang-questions mailing list
>> 
>> http://erlang.org/mailman/**listinfo/erlang-questions<http://erlang.org/mailman/listinfo/erlang-questions>
>>
>
>
> --
> Loïc Hoguin
> Erlang Cowboy
> Nine Nines
>
> ______________________________**_________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/**listinfo/erlang-questions<http://erlang.org/mailman/listinfo/erlang-questions>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120320/51ed289e/attachment.html>


More information about the erlang-questions mailing list