DOCUMENTATION/API_RENDER.md in nephos-server-0.6.3 vs DOCUMENTATION/API_RENDER.md in nephos-server-0.6.4
- old
+ new
@@ -1,9 +1,8 @@
# Render API
## Understand the API
-
The render API is a simple system to allows you to render HTTP responses to a client.
The API allows you to customize differents parts of the response:
- HTTP status
- HTTP Content-Type
@@ -11,26 +10,25 @@
The API use the returns of the Controllers methods to build the HTTP responses.
## Use the API
-
To use the API, you have to create a new controller.
-The controller must be placed or requires in the ``app/`` directory,
-via a ``file.rb`` file.
-It must contain a class, wich inherit from ``Nephos::Controller``.
-Each public method can be an entry point, defined in the ``routes.rb`` file.
-[Routing doc](GUIDE_ROUTING.md).
+The controller must be placed or requires in the ``app/`` directory. Check the
+[Guide about the controller](GUIDE_CONTROLLER.md).
+It must contain a class, inheriting from ``Nephos::Controller``.
+Each public method **can** be an entry point, defined in the ``routes.rb`` file.
+[Routing documentation](GUIDE_ROUTING.md).
+
In the controller, you can use few helpers,
-like the method ``params()``, ``env()``, and ``infos()``
+like the method ``params()`` and ``cookies``
The methods used as entry point must return a ``Hash`` described in the following lines.
It may optionnaly be an ``Integer``, to return only a status, or ``:empty``.
## Options
-
The returns of a Controller method can include the following keys:
- :plain
- :html
- :json
@@ -55,51 +53,45 @@
```
The following sections will describe how each key works and modify the HTTP response.
### Content
-
The ``:content`` key must be associated with a ``String`` (or ``Hash`` is json).
**Optionnal**:
a default value is provided, based on the ``:status`` if no ``:content`` if specified.
### Type
-
The ``:type`` key has to be associated with a ``String`` matching with **"kind/type"**.
**Optionnal**:
the default value is ``text/plain``
Kinds and Types (called type and sub-type by w3c) are described here:
[the w3c documentation](http://www.w3.org/Protocols/rfc1341/4_Content-Type.html)
#### Kind:
-
- image
- text
- ...
#### Type:
-
- plain
- javascript
- jpeg
- ...
### Status
-
The ``:status`` key is associable with an Integer. It must represent the HTTP status code.
**Optionnal**:
The default value is 200.
[The complete HTTP status code list](https://en.wikipedia.org/wiki/List_of_HTTP_status_codes)
### Plain, HTML, JSON
-
The keys ``:plain``, ``:html``, ``:json`` can replace both ``:content`` ``:type``.
It is associated like ``:content`` and **replace automaticaly the type**.
key | type
---|---