@@ -11,25 +11,54 @@ and frustrating. Let's look at an example::
1111
1212 app = Flask(__name__)
1313 db = SQLAlchemy(app)
14- FlaskJSONAPI(app, db)
14+ api = FlaskJSONAPI(app, db)
1515
1616And after all that work, you should now have a full working API.
1717
1818Signals
1919=======
2020
21+ As Flask makes use of signals via Blinker, it would be appropriate to make use
22+ of them in the Flask module for SQLALchemy-JSONAPI. If a signal receiver
23+ returns a value, it can alter the final response.
24+
2125on_request
2226----------
2327
28+ Triggered before serialization::
29+
30+ @api.on_request.connect
31+ def process_api_request(sender, method, endpoint, data, req_args):
32+ # Handle the request
33+
2434on_success
2535----------
2636
37+ Triggered after successful serialization::
38+
39+ @api.on_success.connect
40+ def process_api_success(sender, method, endpoint, data, req_args, response):
41+ # Handle the response dictionary
42+
43+
2744on_error
2845--------
2946
47+ Triggered after failed handling::
48+
49+ @api.on_error.connect
50+ def process_api_error(sender, method, endpoint, data, req_args, error):
51+ # Handle the error
52+
3053on_response
3154-----------
3255
56+ Triggered after rendering of response::
57+
58+ @api.on_response.connect
59+ def process_api_response(sender, method, endpoint, data, req_args, rendered_response):
60+ # Handle the rendered response
61+
3362API
3463===
3564
0 commit comments