An API returns an marshmallow.Schema object or a list of dictionaries as usually to jsonify parameter like:
from marshmallow import Schema
schema.dump(query.items, many=True)
jsonify(result)
Create a output:
[
{
"id": 1,
"name": "Avengers",
"pub_date": "2020-01-20"
},
{
"id": 3,
"name": "Iron Man 2",
"pub_date": "2010-05-02"
}
]
But the standard jsonapi say that the response MUST be like:
{
"links": {
"self": "http://example.com/articles",
"next": "http://example.com/articles?page[offset]=2",
"last": "http://example.com/articles?page[offset]=10"
},
"data": [{
"id": 1,
"name": "Avengers",
"pub_date": "2020-01-20"
},
{
"id": 3,
"name": "Iron Man 2",
"pub_date": "2010-05-02"
}
]}
}
Create a wrapper over jsonfy to accept a SQLAlchemy paginated instance and a list of elements and create this JSON object?
An example of lask-rest-api:
https://github.com/Nobatek/flask-rest-api/blob/master/flask_rest_api/pagination.py
An API returns an marshmallow.Schema object or a list of dictionaries as usually to jsonify parameter like:
Create a output:
[ { "id": 1, "name": "Avengers", "pub_date": "2020-01-20" }, { "id": 3, "name": "Iron Man 2", "pub_date": "2010-05-02" } ]But the standard jsonapi say that the response MUST be like:
{ "links": { "self": "http://example.com/articles", "next": "http://example.com/articles?page[offset]=2", "last": "http://example.com/articles?page[offset]=10" }, "data": [{ "id": 1, "name": "Avengers", "pub_date": "2020-01-20" }, { "id": 3, "name": "Iron Man 2", "pub_date": "2010-05-02" } ]} }Create a wrapper over jsonfy to accept a SQLAlchemy paginated instance and a list of elements and create this JSON object?
An example of lask-rest-api:
https://github.com/Nobatek/flask-rest-api/blob/master/flask_rest_api/pagination.py