From fe3492a98de29942477b061cd02c92246f4bf85a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Mon, 28 Mar 2016 15:36:42 +0200 Subject: Initial commit, new website system --- docs/en/cowboy/2.0/guide/rest_handlers/index.html | 231 ++++++++++++++++++++++ 1 file changed, 231 insertions(+) create mode 100644 docs/en/cowboy/2.0/guide/rest_handlers/index.html (limited to 'docs/en/cowboy/2.0/guide/rest_handlers') diff --git a/docs/en/cowboy/2.0/guide/rest_handlers/index.html b/docs/en/cowboy/2.0/guide/rest_handlers/index.html new file mode 100644 index 00000000..15282e5f --- /dev/null +++ b/docs/en/cowboy/2.0/guide/rest_handlers/index.html @@ -0,0 +1,231 @@ + + + + + + + + + + + + Nine Nines: REST handlers + + + + + + + + + + + + + + + + + + +
+
+
+
+ +

REST handlers

+ +

REST is implemented in Cowboy as a sub protocol. The request +is handled as a state machine with many optional callbacks +describing the resource and modifying the machine’s behavior.

+

The REST handler is the recommended way to handle HTTP requests.

+
+

Initialization

+
+

First, the init/2 callback is called. This callback is common +to all handlers. To use REST for the current request, this function +must return a cowboy_rest tuple.

+
+
+
init(Req, _Opts) ->
+    {cowboy_rest, Req, #state{}}.
+

Cowboy will then switch to the REST protocol and start executing +the state machine.

+

After reaching the end of the flowchart, the terminate/3 callback +will be called if it is defined.

+
+
+
+

Methods

+
+

The REST component has code for handling the following HTTP methods: +HEAD, GET, POST, PATCH, PUT, DELETE and OPTIONS.

+

Other methods can be accepted, however they have no specific callback +defined for them at this time.

+
+
+
+

Callbacks

+
+

All callbacks are optional. Some may become mandatory depending +on what other defined callbacks return. The various flowcharts +in the next chapter should be a useful to determine which callbacks +you need.

+

All callbacks take two arguments, the Req object and the State, +and return a three-element tuple of the form {Value, Req, State}.

+

All callbacks can also return {stop, Req, State} to stop execution +of the request.

+

The following table summarizes the callbacks and their default values. +If the callback isn’t defined, then the default value will be used. +Please look at the flowcharts to find out the result of each return +value.

+

In the following table, "skip" means the callback is entirely skipped +if it is undefined, moving directly to the next step. Similarly, +"none" means there is no default value for this callback.

+
+ +++ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Callback name Default value

allowed_methods

[<<"GET">>, <<"HEAD">>, <<"OPTIONS">>]

allow_missing_post

true

charsets_provided

skip

content_types_accepted

none

content_types_provided

`$$[

+
+
+
+ + + +
+ +
+ + +

+ Cowboy + 2.0 + + User Guide +

+ + + +

Navigation

+ +

Version select

+ + +
+
+
+
+ + + + + + + + + + + + -- cgit v1.2.3