Add a stub chapter with all the REST flowcharts
The detailed explanations will be written at a later time.
BIN
guide/rest_cond.png
Normal file
After Width: | Height: | Size: 109 KiB |
BIN
guide/rest_conneg.png
Normal file
After Width: | Height: | Size: 76 KiB |
BIN
guide/rest_delete.png
Normal file
After Width: | Height: | Size: 119 KiB |
42
guide/rest_flowcharts.md
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
REST flowcharts
|
||||||
|
===============
|
||||||
|
|
||||||
|
This chapter will explain the REST handler state machine through
|
||||||
|
a number of different diagrams.
|
||||||
|
|
||||||
|
This chapter is still under construction.
|
||||||
|
|
||||||
|
Start
|
||||||
|
-----
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
OPTIONS method
|
||||||
|
--------------
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Content negotiation
|
||||||
|
-------------------
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
GET and HEAD methods
|
||||||
|
--------------------
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
PUT, POST and PATCH methods
|
||||||
|
---------------------------
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
DELETE method
|
||||||
|
-------------
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Conditional requests
|
||||||
|
--------------------
|
||||||
|
|
||||||
|

|
BIN
guide/rest_get_head.png
Normal file
After Width: | Height: | Size: 98 KiB |
|
@ -1,22 +1,14 @@
|
||||||
REST handlers
|
REST handlers
|
||||||
=============
|
=============
|
||||||
|
|
||||||
Purpose
|
|
||||||
-------
|
|
||||||
|
|
||||||
REST is a set of constraints that, when applied to HTTP, dictates how
|
|
||||||
resources must behave. It is the recommended way to handle requests
|
|
||||||
with Cowboy.
|
|
||||||
|
|
||||||
REST is implemented in Cowboy as a protocol upgrade. Once upgraded,
|
REST is implemented in Cowboy as a protocol upgrade. Once upgraded,
|
||||||
the request is handled as a state machine with many optional callbacks
|
the request is handled as a state machine with many optional callbacks
|
||||||
describing the resource and modifying the machine's behavior.
|
describing the resource and modifying the machine's behavior.
|
||||||
|
|
||||||
As the REST handler is still subject to change, the documentation is
|
The REST handler is the recommended way to handle requests.
|
||||||
still thin. This state of affair will be improved in the coming weeks.
|
|
||||||
|
|
||||||
Usage
|
Initialization
|
||||||
-----
|
--------------
|
||||||
|
|
||||||
Like Websocket, REST is a sub-protocol of HTTP. It therefore
|
Like Websocket, REST is a sub-protocol of HTTP. It therefore
|
||||||
requires a protocol upgrade.
|
requires a protocol upgrade.
|
||||||
|
@ -27,16 +19,9 @@ init({tcp, http}, Req, Opts) ->
|
||||||
```
|
```
|
||||||
|
|
||||||
Cowboy will then switch to the REST protocol and start executing
|
Cowboy will then switch to the REST protocol and start executing
|
||||||
the flow diagram, starting from `rest_init/2` if it's defined,
|
the state machine, starting from `rest_init/2` if it's defined,
|
||||||
and ending with `rest_terminate/2` also if defined.
|
and ending with `rest_terminate/2` also if defined.
|
||||||
|
|
||||||
Flow diagram
|
|
||||||
------------
|
|
||||||
|
|
||||||
Not done yet. Feel free to use the one that is currently being worked on.
|
|
||||||
|
|
||||||
* https://github.com/extend/cowboy/pull/364
|
|
||||||
|
|
||||||
Methods
|
Methods
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
@ -50,8 +35,9 @@ Callbacks
|
||||||
---------
|
---------
|
||||||
|
|
||||||
All callbacks are optional. Some may become mandatory depending
|
All callbacks are optional. Some may become mandatory depending
|
||||||
on what other defined callbacks return. The flow diagram should
|
on what other defined callbacks return. The various flowcharts
|
||||||
be a pretty good resource to determine which callbacks you need.
|
in the next chapter should be a useful to determine which callbacks
|
||||||
|
you need.
|
||||||
|
|
||||||
When the request starts being processed, Cowboy will call the
|
When the request starts being processed, Cowboy will call the
|
||||||
`rest_init/2` function if it is defined, with the Req object
|
`rest_init/2` function if it is defined, with the Req object
|
||||||
|
@ -69,7 +55,7 @@ tuple of the form `{Value, Req, State}`.
|
||||||
|
|
||||||
The following table summarizes the callbacks and their default values.
|
The following table summarizes the callbacks and their default values.
|
||||||
If the callback isn't defined, then the default value will be used.
|
If the callback isn't defined, then the default value will be used.
|
||||||
Please look at the flow diagram to find out the result of each return
|
Please look at the flowcharts to find out the result of each return
|
||||||
value.
|
value.
|
||||||
|
|
||||||
All callbacks can also return `{halt, Req, State}` to stop execution
|
All callbacks can also return `{halt, Req, State}` to stop execution
|
||||||
|
|
BIN
guide/rest_options.png
Normal file
After Width: | Height: | Size: 8.3 KiB |
BIN
guide/rest_put_post_patch.png
Normal file
After Width: | Height: | Size: 214 KiB |
BIN
guide/rest_start.png
Normal file
After Width: | Height: | Size: 115 KiB |
|
@ -34,11 +34,7 @@ REST
|
||||||
|
|
||||||
* [REST principles](rest_principles.md)
|
* [REST principles](rest_principles.md)
|
||||||
* [Handling REST requests](rest_handlers.md)
|
* [Handling REST requests](rest_handlers.md)
|
||||||
* HEAD/GET requests flowchart
|
* [REST flowcharts](rest_flowcharts.md)
|
||||||
* POST/PUT/PATCH requests flowchart
|
|
||||||
* DELETE requests flowchart
|
|
||||||
* OPTIONS requests flowchart
|
|
||||||
* Designing a REST API
|
|
||||||
|
|
||||||
Multipart
|
Multipart
|
||||||
---------
|
---------
|
||||||
|
|