diff options
author | Loïc Hoguin <[email protected]> | 2013-04-26 14:12:29 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2013-04-26 14:12:29 +0200 |
commit | 5291c3eb0ac421994fb3046fc0fcd603b4ea2a64 (patch) | |
tree | 5c10c7b419a2d7785b0aab8671eaa736d4eb3cf6 /guide/rest_handlers.md | |
parent | e73780975c3082381ac71ef119776b0678776d26 (diff) | |
download | cowboy-5291c3eb0ac421994fb3046fc0fcd603b4ea2a64.tar.gz cowboy-5291c3eb0ac421994fb3046fc0fcd603b4ea2a64.tar.bz2 cowboy-5291c3eb0ac421994fb3046fc0fcd603b4ea2a64.zip |
Update the REST chapter of the guide
Diffstat (limited to 'guide/rest_handlers.md')
-rw-r--r-- | guide/rest_handlers.md | 49 |
1 files changed, 34 insertions, 15 deletions
diff --git a/guide/rest_handlers.md b/guide/rest_handlers.md index ac11d98..7e8427e 100644 --- a/guide/rest_handlers.md +++ b/guide/rest_handlers.md @@ -15,6 +15,21 @@ describing the resource and modifying the machine's behavior. As the REST handler is still subject to change, the documentation is still thin. This state of affair will be improved in the coming weeks. +Usage +----- + +Like Websocket, REST is a sub-protocol of HTTP. It therefore +requires a protocol upgrade. + +``` erlang +init({tcp, http}, Req, Opts) -> + {upgrade, protocol, cowboy_rest}. +``` + +Cowboy will then switch to the REST protocol and start executing +the flow diagram, starting from `rest_init/2` if it's defined, +and ending with `rest_terminate/2` also if defined. + Flow diagram ------------ @@ -70,7 +85,7 @@ empty column means there is no default value for this callback. | allow_missing_post | `true` | | charsets_provided | skip | | content_types_accepted | | -| content_types_provided | | +| content_types_provided | `[{{<<"text">>, <<"html">>, '*'}, to_html}] ` | | delete_completed | `true` | | delete_resource | `false` | | expires | `undefined` | @@ -106,6 +121,9 @@ each function. For example, `from_html` and `to_html` indicate in the first case that we're accepting a resource given as HTML, and in the second case that we send one as HTML. +Meta data +--------- + Cowboy will set informative meta values at various points of the execution. You can retrieve them using `cowboy_req:meta/{2,3}`. The values are defined in the following table. @@ -119,17 +137,18 @@ The values are defined in the following table. They can be used to reply a response entity to a request with an idempotent method (`POST`, `PUT`, `PATCH`, `DELETE`). -Usage ------ - -Like Websocket, REST is a sub-protocol of HTTP. It therefore -requires a protocol upgrade. - -``` erlang -init({tcp, http}, Req, Opts) -> - {upgrade, protocol, cowboy_rest}. -``` - -Cowboy will then switch to the REST protocol and start executing -the flow diagram, starting from `rest_init/2` if it's defined, -and ending with `rest_terminate/2` also if defined. +Response headers +---------------- + +Cowboy will set response headers automatically over the execution +of the REST code. They are listed in the following table. + +| Header name | Details | +| ---------------- | -------------------------------------------------- | +| content-language | Language used in the response body | +| content-type | Media type and charset of the response body | +| etag | Etag of the resource | +| expires | Expiration date of the resource | +| last-modified | Last modification date for the resource | +| location | Relative or absolute URI to the requested resource | +| vary | List of headers that may change the representation of the resource | |