You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Flask-COMBO-JSONAPI is a flask extension for building REST APIs. It combines the power of `Flask-Restless <https://flask-restless.readthedocs.io/>`_ and the flexibility of `Flask-RESTful <https://flask-restful.readthedocs.io/>`_ around a strong specification `JSONAPI 1.0 <http://jsonapi.org/>`_. This framework is designed to quickly build REST APIs and fit the complexity of real life projects with legacy data and multiple data storages.
11
16
12
-
The main goal is to make it flexible using `plugin system <https://github.com/AdCombo/combojsonapi/blob/develop/docs/en/create_plugins.rst>`_
17
+
The main goal is to make it flexible using `plugin system <https://combojsonapi.readthedocs.io/>`_
13
18
14
19
15
20
Install
16
21
=======
17
22
18
23
pip install Flask-COMBO-JSONAPI
19
24
20
-
Installation from pypi is not ready yet. Refer to the `installation manual <https://github.com/AdCombo/flask-combo-jsonapi/blob/develop/docs/installation.rst/>`_
21
-
22
25
23
26
A minimal API
24
27
=============
@@ -28,23 +31,27 @@ A minimal API
28
31
from flask import Flask
29
32
from flask_combo_jsonapi import Api, ResourceDetail, ResourceList
30
33
from flask_sqlalchemy import SQLAlchemy
34
+
from marshmallow import pre_load
31
35
from marshmallow_jsonapi.flask import Schema
32
36
from marshmallow_jsonapi import fields
33
37
34
38
# Create the Flask application and the Flask-SQLAlchemy object.
Copy file name to clipboardExpand all lines: docs/data_layer.rst
+13-9Lines changed: 13 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -5,13 +5,13 @@ Data layer
5
5
6
6
.. currentmodule:: flask_combo_jsonapi
7
7
8
-
|The data layer is a CRUD interface between resource manager and data. It is a very flexible system to use any ORM or data storage. You can even create a data layer that use multiple ORMs and data storage to manage your own objects. The data layer implements a CRUD interface for objects and relationships. It also manage pagination, filtering and sorting.
8
+
|The data layer is a CRUD interface between resource manager and data. It is a very flexible system to use any ORM or data storage. You can even create a data layer that uses multiple ORMs and data storage to manage your own objects. The data layer implements a CRUD interface for objects and relationships. It also manages pagination, filtering and sorting.
9
9
|
10
-
|Flask-COMBO-JSONAPI has a fullfeatured data layer that use the popular ORM `SQLAlchemy <https://www.sqlalchemy.org/>`_.
10
+
|Flask-COMBO-JSONAPI has a full-featured data layer that uses the popular ORM `SQLAlchemy <https://www.sqlalchemy.org/>`_.
11
11
12
12
.. note::
13
13
14
-
The default data layer used by a resource manager is the SQLAlchemy one. So if you want to use it, you don't have to specify the class of the data layer in the resource manager
14
+
The default data layer used by a resource manager is the SQLAlchemy one. So if that's what you want to use, you don't have to specify the class of the data layer in the resource manager
15
15
16
16
To configure the data layer you have to set its required parameters in the resource manager.
17
17
@@ -28,11 +28,13 @@ Example:
28
28
data_layer = {'session': db.session,
29
29
'model': Person}
30
30
31
-
You can also plug additional methods to your data layer in the resource manager. There are two kinds of additional methods:
31
+
You can also plug additional methods into your data layer in the resource manager. There are two kinds of additional methods:
32
32
33
-
* query: the "query" additional method takes view_kwargs as parameter and return an alternative query to retrieve the collection of objects in the GET method of the ResourceList manager.
33
+
* query: the "query" additional method takes view_kwargs as parameter and returns an alternative query to retrieve the collection of objects in the GET method of the ResourceList manager.
34
34
35
-
* pre / post process methods: all CRUD and relationship(s) operations have a pre / post process methods. Thanks to it you can make additional work before and after each operations of the data layer. Parameters of each pre / post process methods are available in the `flask_combo_jsonapi.data_layers.base.Base <https://github.com/AdCombo/flask-combo-jsonapi/blob/master/flask_combo_jsonapi/data_layers/base.py>`_ base class.
35
+
* pre-/postprocess methods: all CRUD and relationship(s) operations have pre-/postprocess methods.
36
+
Thanks to these you can do additional work before and after each operation of the data layer.
37
+
Parameters of each pre-/postprocess method are available in the `flask_combo_jsonapi.data_layers.base.Base <https://github.com/AdCombo/flask-combo-jsonapi/blob/master/flask_combo_jsonapi/data_layers/base.py>`_ base class.
36
38
37
39
Example:
38
40
@@ -68,7 +70,7 @@ Example:
68
70
69
71
.. note::
70
72
71
-
You don't have to declare additional data layer methods in the resource manager. You can declare them in a dedicated module or in the declaration of the model.
73
+
You don't have to declare additional data layer methods in the resource manager. You can declare them in a dedicated module or in the model's declaration.
72
74
73
75
Example:
74
76
@@ -100,12 +102,14 @@ Optional parameters:
100
102
:id_field: the field used as identifier field instead of the primary key of the model
101
103
:url_field: the name of the parameter in the route to get value to filter with. Instead "id" is used.
102
104
103
-
By default SQLAlchemy eagerload related data specified in include querystring parameter. If you want to disable this feature you must add eagerload_includes: False to data layer parameters.
105
+
By default SQLAlchemy eagerly loads related data specified in the include query string parameter. If you want to disable this feature you must add eagerload_includes: False to the data layer parameters.
104
106
105
107
Custom data layer
106
108
-----------------
107
109
108
-
Like I said previously you can create and use your own data layer. A custom data layer must inherit from `flask_combo_jsonapi.data_layers.base.Base <https://github.com/AdCombo/flask-combo-jsonapi/blob/master/flask_combo_jsonapi/data_layers/base.py>`_. You can see the full scope of possibilities of a data layer in this base class.
110
+
As previously mentioned, you can create and use your own data layer.
111
+
A custom data layer must inherit from `flask_combo_jsonapi.data_layers.base.Base <https://github.com/AdCombo/flask-combo-jsonapi/blob/master/flask_combo_jsonapi/data_layers/base.py>`_.
112
+
You can see the full scope of possibilities of a data layer in this base class.
Copy file name to clipboardExpand all lines: docs/errors.rst
+6-6Lines changed: 6 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ Errors
5
5
6
6
.. currentmodule:: flask_combo_jsonapi
7
7
8
-
JSONAPI 1.0 specification recommand to return errors like that:
8
+
The JSON:API 1.0 specification recommends to return errors like this:
9
9
10
10
.. sourcecode:: http
11
11
@@ -28,9 +28,9 @@ JSONAPI 1.0 specification recommand to return errors like that:
28
28
}
29
29
}
30
30
31
-
The "source" field gives information about the error if it is located in data provided or in querystring parameter.
31
+
The "source" field gives information about the error if it is located in data provided or in a query string parameter.
32
32
33
-
The previous example displays error located in data provided instead of this next example displays error located in querystring parameter "include":
33
+
The previous example shows an error located in data provided. The following example shows error in the query string parameter "include":
34
34
35
35
.. sourcecode:: http
36
36
@@ -53,13 +53,13 @@ The previous example displays error located in data provided instead of this nex
53
53
}
54
54
}
55
55
56
-
Flask-COMBO-JSONAPI provides two kind of helpers to achieve error displaying:
56
+
Flask-COMBO-JSONAPI provides two kinds of helpers for displaying errors:
57
57
58
58
|* **the errors module**: you can import jsonapi_errors from the `errors module <https://github.com/AdCombo/flask-combo-jsonapi/blob/master/flask_combo_jsonapi/errors.py>`_ to create the structure of a list of errors according to JSONAPI 1.0 specification
59
59
|
60
-
|* **the exceptions module**: you can import lot of exceptions from this `module <https://github.com/AdCombo/flask-combo-jsonapi/blob/master/flask_combo_jsonapi/exceptions.py>`_ that helps you to raise exceptions that will be wellformatted according to JSONAPI 1.0 specification
60
+
|* **the exceptions module**: you can import a lot of exceptions from this `module <https://github.com/AdCombo/flask-combo-jsonapi/blob/master/flask_combo_jsonapi/exceptions.py>`_ that helps you to raise exceptions that will be well-formatted according to the JSON:API 1.0 specification
61
61
62
-
When you create custom code for your api I recommand to use exceptions from exceptions module of Flask-COMBO-JSONAPIto raise errors because JsonApiExceptionbased exceptions are catched and rendered according to JSONAPI 1.0 specification.
62
+
When you create custom code for your API I recommand using exceptions from the Flask-COMBO-JSONAPI's exceptions module to raise errors because JsonApiException-based exceptions are caught and rendered according to the JSON:API 1.0 specification.
Copy file name to clipboardExpand all lines: docs/filtering.rst
+38-33Lines changed: 38 additions & 33 deletions
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,12 @@ Filtering
5
5
6
6
.. currentmodule:: flask_combo_jsonapi
7
7
8
-
Flask-COMBO-JSONAPI as a very flexible filtering system. The filtering system is completely related to the data layer used by the ResourceList manager. I will explain the filtering interface for SQLAlchemy data layer but you can use the same interface to your filtering implementation of your custom data layer. The only requirement is that you have to use the "filter" querystring parameter to make filtering according to the JSONAPI 1.0 specification.
8
+
Flask-COMBO-JSONAPI has a very flexible filtering system.
9
+
The filtering system is directly attached to the data layer used by the ResourceList manager.
10
+
These examples show the filtering interface for SQLAlchemy's data layer
11
+
but you can use the same interface for your custom data layer's filtering implementation as well.
12
+
The only requirement is that you have to use the "filter" query string parameter
13
+
to filter according to the JSON:API 1.0 specification.
9
14
10
15
.. note::
11
16
@@ -14,19 +19,19 @@ Flask-COMBO-JSONAPI as a very flexible filtering system. The filtering system is
14
19
SQLAlchemy
15
20
----------
16
21
17
-
The filtering system of SQLAlchemy data layer has exactly the same interface as the filtering system of `Flask-Restless <https://flask-restless.readthedocs.io/en/stable/searchformat.html#query-format>`_.
22
+
The filtering system of SQLAlchemy's data layer has exactly the same interface as the one used in `Flask-Restless <https://flask-restless.readthedocs.io/en/stable/searchformat.html#query-format>`_.
18
23
So this is a first example:
19
24
20
25
.. sourcecode:: http
21
26
22
27
GET /persons?filter=[{"name":"name","op":"eq","val":"John"}] HTTP/1.1
23
28
Accept: application/vnd.api+json
24
29
25
-
In this example we want to retrieve persons which name is John. So we can see that the filtering interface completely fit the filtering interface of SQLAlchemy: a list a filter information.
30
+
In this example we want to retrieve person records for people named John. So we can see that the filtering interface completely fits that of SQLAlchemy: a list a filter information.
26
31
27
32
:name: the name of the field you want to filter on
28
-
:op: the operation you want to use (all sqlalchemy operations are available)
29
-
:val: the value that you want to compare. You can replace this by "field" if you want to compare against the value of an other field
33
+
:op: the operation you want to use (all SQLAlchemy operations are available)
34
+
:val: the value that you want to compare. You can replace this by "field" if you want to compare against the value of another field
30
35
31
36
Example with field:
32
37
@@ -35,7 +40,7 @@ Example with field:
35
40
GET /persons?filter=[{"name":"name","op":"eq","field":"birth_date"}] HTTP/1.1
36
41
Accept: application/vnd.api+json
37
42
38
-
In this example, we want to retrieve persons that name is equal to his birth_date. I know, this example is absurd but it is just to explain the syntax of this kind of filter.
43
+
In this example, we want to retrieve people whose name is equal to their birth_date. This example is absurd, it's just here to explain the syntax of this kind of filter.
39
44
40
45
If you want to filter through relationships you can do that:
41
46
@@ -56,9 +61,9 @@ If you want to filter through relationships you can do that:
56
61
57
62
.. note ::
58
63
59
-
When you filter on relationships use "any" operator for "to many" relationships and "has" operator for "to one" relationships.
64
+
When you filter on relationships use the "any" operator for "to many" relationships and the "has" operator for "to one" relationships.
60
65
61
-
There is a shortcut to achieve the same filter:
66
+
There is a shortcut to achieve the same filtering:
62
67
63
68
.. sourcecode:: http
64
69
@@ -107,36 +112,36 @@ You can also use boolean combination of operations:
107
112
108
113
Common available operators:
109
114
110
-
* any: used to filter on to many relationships
115
+
* any: used to filter on "to many" relationships
111
116
* between: used to filter a field between two values
112
-
* endswith: check if field ends with a string
113
-
* eq: check if field is equal to something
114
-
* ge: check if field is greater than or equal to something
115
-
* gt: check if field is greater than to something
116
-
* has: used to filter on to one relationships
117
-
* ilike: check if field contains a string (case insensitive)
118
-
* in\_: check if field is in a list of values
119
-
* is\_: check if field is a value
120
-
* isnot: check if field is not a value
121
-
* like: check if field contains a string
122
-
* le: check if field is less than or equal to something
123
-
* lt: check if field is less than to something
124
-
* match: check if field match against a string or pattern
125
-
* ne: check if field is not equal to something
126
-
* notilike: check if field does not contains a string (case insensitive)
127
-
* notin\_: check if field is not in a list of values
128
-
* notlike: check if field does not contains a string
129
-
* startswith: check if field starts with a string
117
+
* endswith: checks if field ends with a string
118
+
* eq: checks if field is equal to something
119
+
* ge: checks if field is greater than or equal to something
120
+
* gt: checks if field is greater than something
121
+
* has: used to filter on "to one" relationships
122
+
* ilike: checks if field contains a string (case insensitive)
123
+
* in\_: checks if field is in a list of values
124
+
* is\_: checks if field is a value
125
+
* isnot: checks if field is not a value
126
+
* like: checks if field contains a string
127
+
* le: checks if field is less than or equal to something
128
+
* lt: checks if field is less than something
129
+
* match: checks if field matches against a string or pattern
130
+
* ne: checks if field is not equal to something
131
+
* notilike: checks if field does not contain a string (case insensitive)
132
+
* notin\_: checks if field is not in a list of values
133
+
* notlike: checks if field does not contain a string
134
+
* startswith: checks if field starts with a string
130
135
131
136
.. note::
132
137
133
-
Availables operators depend on field type in your model
138
+
Available operators depend on the field type in your model
134
139
135
140
Simple filters
136
141
--------------
137
142
138
-
Simple filter adds support for a simplified form of filters and supports only *eq* operator.
139
-
Each simple filter transforms to original filter and appends to list of filters.
143
+
Simple filters add support for a simplified form of filters and support only the *eq* operator.
144
+
Each simple filter is transformed into a full filter and appended to the list of filters.
140
145
141
146
For example
142
147
@@ -145,22 +150,22 @@ For example
145
150
GET /persons?filter[name]=John HTTP/1.1
146
151
Accept: application/vnd.api+json
147
152
148
-
equals to:
153
+
equals:
149
154
150
155
.. sourcecode:: http
151
156
152
157
GET /persons?filter[name]=[{"name":"name","op":"eq","val":"John"}] HTTP/1.1
153
158
Accept: application/vnd.api+json
154
159
155
160
156
-
You can also use more than one simple filter in request:
161
+
You can also use more than one simple filter in a request:
157
162
158
163
.. sourcecode:: http
159
164
160
165
GET /persons?filter[name]=John&filter[gender]=male HTTP/1.1
0 commit comments