Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support jsonapi #82

Open
avara1986 opened this issue Jan 21, 2020 · 0 comments
Open

Support jsonapi #82

avara1986 opened this issue Jan 21, 2020 · 0 comments
Labels
feature New feature in progres help wanted Extra attention is needed

Comments

@avara1986
Copy link
Member

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

@avara1986 avara1986 added feature New feature in progres help wanted Extra attention is needed labels Jan 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature in progres help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant