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

Add support routes for hybrid_methods #506

Open dwiel opened 8 years ago

dwiel commented 8 years ago

It would be nice for hybrid_methods to be available in a form something like this:

class Location():
    @hybrid_method
    def temperature(self, day):
        return weather.temperature(self.zipcode, day)

# available in the API as:
/api/locations/:id/temperature?day=2016-01-01

# also potentially available in the API as a column on locations, which would then require that /locations/:id accept a day param

We're building out something like this on top of flask-restless, but if there was a pattern that would be accepted as a PR, we can build it that way instead. Is a Pull Request that implements the above pattern something that would be accepted?

jfinkels commented 8 years ago

Interesting. Flask-Restless will support the JSON API protocol in the next release; does this cause any problem with that? I'm not sure it makes sense to have a temperature attribute when fetching a Location resource, since the day query parameter doesn't apply to the resource represented by the URL, it really applies to the temperature resource.

I don't see any obvious reason why it couldn't work. Make sure your pull request has tests, probably in the tests/test_fetching.py module.

dwiel commented 8 years ago

I'm not sure about JSON API issues. Is there a branch or something we should test against? I agree that the example is not the best. Thanks

jfinkels commented 8 years ago

You will see when you clone the master branch that the code is very different from version 0.17.0.