Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a4918ae

Browse files
committed
Add small API documentation
1 parent 9370767 commit a4918ae

File tree

2 files changed

+70
-26
lines changed

2 files changed

+70
-26
lines changed

docs/plugins/api.rst

Lines changed: 54 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,69 @@
1-
.. note::
2-
3-
This documentation is under construction, more to come soon
4-
5-
6-
71
Api
82
===
93

10-
expose your data through a json api
11-
124
Features
13-
~~~~~~~~
5+
--------
146

15-
- Insert here the different feature available for this plugin
7+
- Expose node from the datasource through a RESTful API.
168

179
Configuration
18-
~~~~~~~~~~~~~
10+
-------------
11+
12+
You need to enable the plugin by adding this line into the IoC configuration file.
13+
14+
.. code-block:: yaml
15+
16+
element.plugins.api:
1917
20-
- Insert the yaml configuration for the DI
18+
Then, you must have a node api as defined in your datasource:
2119

2220
.. code-block:: yaml
2321
24-
element.plugins.cache:
25-
cache_control:
26-
- { "path": "^.*\\.(txt|jpg|png|gif|xls|doc|docx)$", "Cache-Control": ['public', 's-maxage=14212800']}
27-
- { "path": "^(blog|gallery).*", "Cache-Control": ['public', 's-maxage=3600']}
28-
- { "path": "^.*\\.rss", "Cache-Control": ['public', 's-maxage=3600']}
29-
- { "path": "^contact.*", "Cache-Control": ['private', 'must-revalidate']}
30-
- { "path": "^/$", "Cache-Control": ['public', 's-maxage=3600']}
22+
# api.yml
23+
title: API
24+
type: action.collection
25+
actions:
26+
element_api_node:
27+
path: /element/node/<path:path>.<_format>
28+
methods: ['GET', 'PUT', 'POST', 'DELETE']
29+
defaults:
30+
_controller: element.api.view.node:execute
31+
32+
element_api_list_index:
33+
path: /element/node.<_format>
34+
methods: ['GET']
35+
defaults:
36+
_controller: element.api.view.node.list:execute
37+
path: /
38+
39+
element_api_list:
40+
path: /element/path/<path:path>.<_format>
41+
methods: ['GET']
42+
defaults:
43+
_controller: element.api.view.node.list:execute
3144
32-
Events
33-
~~~~~~
45+
element_api_handler_list:
46+
path: /element/handlers.<_format>
47+
methods: ['GET']
48+
defaults:
49+
_controller: element.api.view.handler.list:execute
50+
51+
element_api_handler:
52+
path: /element/handler/<code>.<_format>
53+
methods: ['GET']
54+
defaults:
55+
_controller: element.api.view.handler:execute
56+
57+
58+
.. note::
3459

35-
- List event or entry points for this plugin
60+
The API is not stable.
3661

37-
Architecture
38-
~~~~~~~~~~~~
62+
Usage
63+
-----
3964

40-
- Provide information about how the feature is implemented
65+
- ``GET /api/element/handlers.json`` : return the list of handlers
66+
- ``GET /api/element/node.json``: return the different node available
67+
- ``GET /api/element/node/{ID}.json``: get a node
68+
- ``POST /api/element/node/{ID}.json``: update a node
69+
- ``PUT /api/element/node/{ID}.json``: create a node

element/plugins/api/views.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,22 @@ def get(self, context, path, **kwargs):
8686
'results': []
8787
}
8888

89-
for node in self.node_manager.get_nodes(path=path):
89+
limit = 32
90+
offset = 0
91+
92+
if "limit" in kwargs:
93+
limit = int(kwargs["limit"])
94+
95+
if "offset" in kwargs:
96+
offset = int(kwargs["offset"])
97+
98+
if limit > 32 or limit < 0:
99+
limit = 32
100+
101+
if offset < 0:
102+
offset = 0
103+
104+
for node in self.node_manager.get_nodes(path=path, limit=limit, offset=offset):
90105
data['results'].append(self.serialize_node(node))
91106

92107
return data, 200

0 commit comments

Comments
 (0)