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

Forward a POST request to a GET endpoint #680

Closed Marius-Stroe closed 6 years ago

Marius-Stroe commented 6 years ago

Hello,

I'm using Flask-Restless==1.0.0b1 with Flask-SQLAlchemy. What I like about it is that it provides JSON API 1.0 formatting out of the box.

screen shot 2018-02-04 at 11 54 05 pm

My setup is the following:

It would be something like the below. But the problem is that redirect doesn't seem to work with a REST api.

from flask import redirect

@app.route('/v1/search', methods=['POST'])
    def search():
        // do stuff
        return redirect('/v1/<some_model>', 'filter[objects]={...}')

Is it possible to do this kind of redirection? Thank you

PS: You may be asking why I don't query the <some_model> directly and return the results. It's because I don't get the uniform JSON API 1.0 formatting. I could use marshmallow-jsonapi and marshmallow-sqlalchemy, but look https://github.com/marshmallow-code/marshmallow-jsonapi/issues/3 it's a lot more work and not really known how they work together with flask-restless.

Marius-Stroe commented 6 years ago

I have ended up using flask-rest-jsonapi as it decouples the API json formatting from the models.