Skip to content

Support jsonapi #82

Open
Open

Description

@avara1986

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

Activity

  1. added
    feature
    help wanted
    on Jan 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    featurehelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions