jkurtisr32 jkurtisr32 - 1 year ago 84
Python Question

Creating API responses with flask-restless

Let's say I have two models in SqlAlchemy:

  • UserType

  • User

has a foreign key to

I have properly configured flask-restless to serve these models as API endpoints:

  • /api/user

  • /api/user_type

But by default, when I visit either of these endpoints, I get the related data associated with each object in the response:

  • Each
    has the corresponding
    object nested in the response

  • Each
    has a collection of
    nested in the response

This will definitely lead to a lot of overhead as the data grows a lot. If I just want to GET the list of
that the system supports, all of the associated users will come back. Usually an API would generate a link for related resources:

  • /api/user/1/user_type

  • /api/user_type/1/users

Has anyone gotten these links out of flask-restless responses?

Answer Source

It looks like this is a known issue that has been active on GitHub for a long time. Not sure if the developer is planning on fixing it or not:


I ended up going with flask-restful and building my own endpoints.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download