[erlang-questions] cowboy Accept header, rest module

Loïc Hoguin <>
Wed Jun 6 17:41:23 CEST 2012


On 06/06/2012 05:35 PM, Daniel Goertzen wrote:
> I have 2 cowboy questions:
>
> 1. I am trying to parse the Accept header using...
>
>     cowboy_http_req:parse_header('Accept', Req)
>
> The raw header is...
>
> *{'Accept',<<"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8">>}*
> *
> *
> *and the output is ...*
>
> *[{{<<"text">>,<<"html">>,[]},1000,[]},
> {{<<"application">>,<<"xhtml+xml">>,[]},1000,[]},
> {{<<"application">>,<<"xml">>,[]},900,[]},
> {{<<"*">>,<<"*">>,[]},800,[]}]*
>
>
> What do all the parts of the tuple mean? (it is mainly the number that
> is piquing my curiosity)

{{type, subtype, params}, qvalue, extensions}

qvalue is pretty much the 0.9 * 1000, so a value between 0 and 1000 
indicating the weight of the media type.

> 2. I am looking to make a restful web interface using cowboy.  The basic
> cowboy_http_protocol module with its dispatch table seems very nice for
> this, and along with its request parsing I have difficulty imagining
> what more I could need.  What does the cowboy_http_rest module buy you?
>   Note that this is my first web interface in any language and I had
> trouble penetrating the webmachine documentation (I suspect knowing
> nothing about mochiweb is causing problems for me).

It does everything for you automatically. You just need to write a few 
callbacks describing the resource, and all the header/status code jungle 
is done automatically for you following REST conventions.

You can use normal HTTP handlers, but if you're going to write an API 
I'd recommend using REST.

Just check the diagram and resource infos from the Webmachine 
documentation, the rest of it (dispatch, replying and retrieving infos 
about the request) you should look at the Cowboy documentation.

I'm always available for questions, feel free to mail me or open tickets 
if something happens in an unexpected way.

-- 
Loïc Hoguin
Erlang Cowboy
Nine Nines



More information about the erlang-questions mailing list