|
@@ -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 |
|