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
{{ message }}
This repository was archived by the owner on Dec 16, 2025. It is now read-only.
Copy file name to clipboardExpand all lines: docs/data_layer.rst
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,7 +29,9 @@ Example:
29
29
'model': Person}
30
30
31
31
You can also plug additional methods to your data layer in the resource manager. There is 2 kind 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.
34
+
33
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_rest_jsonapi.data_layers.base.Base <https://github.com/miLibris/flask-rest-jsonapi/blob/master/flask_rest_jsonapi/data_layers/base.py>`_ base class.
Copy file name to clipboardExpand all lines: docs/errors.rst
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -55,9 +55,9 @@ The previous example displays error located in data provided instead of this nex
55
55
56
56
Flask-REST-JSONAPI provides two kind of helpers to achieve error displaying:
57
57
58
-
|* **the errors module**: you can import jsonapi_errors from the errors module to create the structure of a list of errors according to JSONAPI 1.0 specification
58
+
|* **the errors module**: you can import jsonapi_errors from the `errors module <https://github.com/miLibris/flask-rest-jsonapi/blob/master/flask_rest_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 that helps you to raise exceptions that will be well formatted according to JSONAPI 1.0 specification
60
+
|* **the exceptions module**: you can import lot of exceptions from this `module <https://github.com/miLibris/flask-rest-jsonapi/blob/master/flask_rest_jsonapi/exceptions.py>`_ that helps you to raise exceptions that will be well formatted according to JSONAPI 1.0 specification
61
61
62
62
When you create custom code for your api I recommand to use exceptions from exceptions module of Flask-REST-JSONAPI to raise errors because JsonApiException based exceptions are catched and rendered according to JSONAPI 1.0 specification.
Copy file name to clipboardExpand all lines: docs/index.rst
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ Main concepts
12
12
:width:600px
13
13
:alt:Architecture
14
14
15
-
|* `JSON API 1.0 specification <http://jsonapi.org/>`_: it is a very popular specification about client server interactions for REST JSON API. It helps you to work in team because it is a very precise and sharable. Thanks to this specification your server will offer lot of features for clients like a strong structure of request and response, filtering, pagination, sparse fieldsets, including related resources, great error formatting etc.
15
+
|* `JSON API 1.0 specification <http://jsonapi.org/>`_: it is a very popular specification about client server interactions for REST JSON API. It helps you to work in team because it is very precise and sharable. Thanks to this specification your api offers lot of features like a strong structure of request and response, filtering, pagination, sparse fieldsets, including related objects, great error formatting etc.
16
16
|
17
17
|* **Logical data abstration**: you usually need to expose resources to clients that don't fit your data table architecture. For example sometimes you don't want to expose all attributes of a table, compute additional attributes or create a resource that use data from multiple data storage. Flask-REST-JSONAPI helps you to create a logical abstraction of your data with `Marshmallow <https://marshmallow.readthedocs.io/en/latest/>`_ / `marshmallow-jsonapi <https://marshmallow-jsonapi.readthedocs.io/>`_ so you can expose your data through a very flexible way.
Copy file name to clipboardExpand all lines: docs/resource_manager.rst
+35-19Lines changed: 35 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@ Resource Manager
7
7
8
8
Resource manager is the link between your logical data abstraction, your data layer and optionally other softwares. It is the place where logic management of your resource is located.
9
9
10
-
Flask-REST-JSONAPI provides 3 kind of resource manager with default methods implementation according to JSONAPI 1.0 specification:
10
+
Flask-REST-JSONAPI provides 3 kinds of resource manager with default methods implementation according to JSONAPI 1.0 specification:
11
11
12
12
|* **ResourceList**: provides get and post methods to retrieve a collection of objects or create one.
13
13
|
@@ -32,6 +32,7 @@ Example:
32
32
from flask_rest_jsonapi import ResourceList
33
33
from your_project.schemas import PersonSchema
34
34
from your_project.models import Person
35
+
from your_project.extensions import db
35
36
36
37
classPersonList(ResourceList):
37
38
schema = PersonSchema
@@ -48,28 +49,28 @@ All resource mangers are inherited from flask.views.MethodView so you can provid
48
49
49
50
You can plug additional decorators to each methods with this optional attributes:
50
51
51
-
:get_decorators: a list a decorators plugged to the get method of the resource manager
52
-
:post_decorators: a list a decorators plugged to the post method of the resource manager
53
-
:patch_decorators: a list a decorators plugged to the patch method of the resource manager
54
-
:delete_decorators: a list a decorators plugged to the delete method of the resource manager
52
+
:get_decorators: a list a decorators plugged to the get method
53
+
:post_decorators: a list a decorators plugged to the post method
54
+
:patch_decorators: a list a decorators plugged to the patch method
55
+
:delete_decorators: a list a decorators plugged to the delete method
55
56
56
57
You can also provides default schema kwargs to each resource manager methods with this optional attributes:
57
58
58
-
:get_schema_kwargs: a dict of default schema instance kwargs in get method
59
-
:post_schema_kwargs: a dict of default schema instance kwargs in post method
60
-
:patch_schema_kwargs: a dict of default schema instance kwargs in patch method
61
-
:delete_schema_kwargs: a dict of default schema instance kwargs in delete method
59
+
:get_schema_kwargs: a dict of default schema kwargs in get method
60
+
:post_schema_kwargs: a dict of default schema kwargs in post method
61
+
:patch_schema_kwargs: a dict of default schema kwargs in patch method
62
+
:delete_schema_kwargs: a dict of default schema kwargs in delete method
62
63
63
64
Each method of a resource manager got a pre and post process methods that take view args and kwargs as parameter for the pre process methods and the result of the method as parameter for the post process method. Thanks to this you can make custom work before and after the method process. Availables rewritable methods are:
64
65
65
-
:before_get(*args, **kwargs): pre process method of the get method
66
-
:after_get(result): post process method of the get method
67
-
:before_post(*args, **kwargs): pre process method of the post method
68
-
:after_post(result): post process method of the post method
69
-
:before_patch(*args, **kwargs): pre process method of the patch method
70
-
:after_patch(result): post process method of the patch method
71
-
:before_delete(*args, **kwargs): pre process method of the delete method
72
-
:after_delete(result): post process method of the delete method
66
+
:before_get: pre process method of the get method
67
+
:after_get: post process method of the get method
68
+
:before_post: pre process method of the post method
69
+
:after_post: post process method of the post method
70
+
:before_patch: pre process method of the patch method
71
+
:after_patch: post process method of the patch method
72
+
:before_delete: pre process method of the delete method
73
+
:after_delete: post process method of the delete method
73
74
74
75
Example:
75
76
@@ -80,6 +81,7 @@ Example:
80
81
from your_project.models import Person
81
82
from your_project.security import login_required
82
83
from your_project.decorators import dummy_decorator
84
+
from your_project.extensions import db
83
85
84
86
classPersonList(ResourceDetail):
85
87
schema = PersonSchema
@@ -88,9 +90,14 @@ Example:
88
90
methods = ['GET', 'PATCH']
89
91
decorators = (login_required, )
90
92
get_decorators = [dummy_decorator]
93
+
get_schema_kwargs = {'only': ('name', )}
91
94
92
95
defbefore_patch(*args, **kwargs):
93
-
"""Make custom work here. View args and kwargs are provided as parameter
96
+
"""Make custom work here. View args and kwargs are provided as parameter
97
+
"""
98
+
99
+
defafter_patch(result):
100
+
"""Make custom work here. Add something to the result of the view.
94
101
"""
95
102
96
103
ResourceList
@@ -105,6 +112,9 @@ Example:
105
112
.. code-block:: python
106
113
107
114
from flask_rest_jsonapi import ResourceList
115
+
from your_project.schemas import PersonSchema
116
+
from your_project.models import Person
117
+
from your_project.extensions import db
108
118
109
119
classPersonList(ResourceList):
110
120
schema = PersonSchema
@@ -123,6 +133,9 @@ Example:
123
133
.. code-block:: python
124
134
125
135
from flask_rest_jsonapi import ResourceDetail
136
+
from your_project.schemas import PersonSchema
137
+
from your_project.models import Person
138
+
from your_project.extensions import db
126
139
127
140
classPersonDetail(ResourceDetail):
128
141
schema = PersonSchema
@@ -131,7 +144,7 @@ Example:
131
144
132
145
This minimal ResourceDetail configuration provides GET, PATCH and DELETE interface to retrieve details of objects, update an objects and delete an object with all powerful features like sparse fieldsets and including related objects.
133
146
134
-
If your schema has relationship(s) field(s) you can update an object and also link(s) to his related object(s) in the same time. If you want to see example go to :ref:`quickstart`.
147
+
If your schema has relationship(s) field(s) you can update an object and also update his link(s) to related object(s) in the same time. If you want to see example go to :ref:`quickstart`.
135
148
136
149
ResourceRelationship
137
150
--------------------
@@ -141,6 +154,9 @@ Example:
141
154
.. code-block:: python
142
155
143
156
from flask_rest_jsonapi import ResourceRelationship
0 commit comments