jfinkels / flask-restless

NO LONGER MAINTAINED - A Flask extension for creating simple ReSTful JSON APIs from SQLAlchemy models.
https://flask-restless.readthedocs.io
GNU Affero General Public License v3.0
1.02k stars 301 forks source link

Allow users to specify relation endpoints #208

Closed jfinkels closed 8 years ago

jfinkels commented 11 years ago

Create a more general framework that allows users to specify which relations will be accessible and at which endpoints. For example,

relations = {'computers': ['GET', 'POST'],
             'computers/<id>': ['GET', 'DELETE', 'PATCH'],
             'computers/<id>/accessories': ['GET']
             'friends': ['GET', 'POST']
             'friends/<id>': ['GET', 'DELETE']}
apimanager.create_api(Person, relations=relations)

which should automatically allow requests like POST /api/person/1/friends. This will require a human hours-intensive rewrite of the code as it stands right now.

jfinkels commented 11 years ago

This would supercede issue #193 and (the already implemented) #2.

jfinkels commented 11 years ago

The problem here would be that requests to /api/person/1/computers/3 won't have the include/exclude field rules.

jfinkels commented 11 years ago

Maybe a more complicated list configuration, like

# A list of three tuples: first the URL fragment, second the list of methods to allow,
# and third a list of fields to include.
relations = [
             ('computers', ['GET', 'POST'], ['id']),
             ('computers/<id>', ['GET', 'DELETE', 'PATCH'], ['id', 'make', 'model']),
             ('computers/<id>/accessories', ['GET'], None),
             ('friends', ['GET', 'POST'], ['id']),
             ('friends/<id>', ['GET', 'DELETE'], ['id', 'name', 'age'])
            ]
klinkin commented 11 years ago

... or even more complex as there http://pythonhosted.org/dictalchemy

relations = [
             ('computers', ['GET', 'POST'], {'exclude': ['id']}),
             ('computers/<id>', ['GET', 'DELETE', 'PATCH'], {'include'=['id', 'make', 'model']}),
             ('computers/<id>/accessories', ['GET'], {'only': ['id', 'model']})
            ]
jfinkels commented 11 years ago

Remember the Zen of Python:

... Simple is better than complex. Complex is better than complicated. ...

klinkin commented 11 years ago

Thx, i know ))

jfinkels commented 11 years ago

It may be nice to incorporate the conventions of dictalchemy. I will look into this.

tom-coefficient commented 10 years ago

@jfinkels it'd be interesting to see dictalchemy conventions work their way in

dnordberg commented 10 years ago

This is what I implemented (Though with a more explicit usage API) in https://github.com/jfinkels/flask-restless/pull/234. Though with much more flexibility in defining what happens at the endpoints.

jfinkels commented 8 years ago

We now only go to /api/person/1/parent or /api/person/1/computers/2 and no further, with CRUD semantics governed by the JSON API protocol, so this is no longer relevant.