Add support for pagination links
There does not appear to be any way to support pagination links (first, prev, next, last) as defined in the spec: https://jsonapi.org/format/#fetching-pagination
I posted a workaround at https://github.com/marshmallow-code/marshmallow-jsonapi/issues/96#issuecomment-371975056, however, this should be implemented.
Requirements:
https://jsonapi.org/format/#fetching-pagination
- To paginate the primary data, supply pagination links in the top-level
linksobject. To paginate an included collection returned in a compound document, supply pagination links in the correspondinglinksobject. - The
pagequery parameter is reserved for pagination. Servers and clients SHOULD use this key for pagination operations. - The following keys MUST be used for pagination links:
first: the first page of datalast: the last page of dataprev: the previous page of datanext: the next page of data
- JSON:API is agnostic about the pagination strategy used by a server.
@sloria Design and implementation:
Schema().dump(items, paginate=True)orSchema().paginate_dump(items)?- How should the pagination data:
first,last, etc be passed for dumping? - General
Schemaandflask.Schemasupport (flask-sqlalchemy pagination object).
thank you.
Hello, Correct if i'm wrong. But adding this functionality to the dump method would also add pagination links to the flask-marshmallow jsonify. I need this and currently i'm doing a work around using the paginate object of the flask-sqlalchemy. If thats the case i can take this issue. Or would be better to create one in the flask-marshmallow project?
It will only add pagination links if you're using marshmallow-jsonapi.Schema as the base for your schemas, rather than flask_marshmallow.Schema
OK, cool. So i will open an issue in the flask-marshmallow project. I guess the solutions will be some what similar, so if i can i will take this one after.
How do I use this workaround in Flask? There are two variables that are undefined in the code sample: ujson and dasherize. Should they be imported from somewhere? It'd be good to include an example on how to invoke the class as well.