python-restx / flask-restx

Fork of Flask-RESTPlus: Fully featured framework for fast, easy and documented API development with Flask
https://flask-restx.readthedocs.io/en/latest/
Other
2.16k stars 335 forks source link

Add pre-flight requests #64

Closed jonatasoli closed 4 years ago

jonatasoli commented 4 years ago

Hello,

Whenever I'm making a request using the axes of the vue I have problems due to the pre-flight call, as it sends an Option before doing the GET / POST / ETC

I think it would be interesting to have an annotation that allows me to enable a pre-flight check on my endpoints.

if you had something like this it would be great:

class SignIn (Resource):
    "" "Sign in User and return jwt token" ""
    @ api.expect (sign_in)
    @ api.marshal_with (auth_user, code = 200)
    @ pre-flight.enabled()
    def post (self):
        "" "Return Login User" ""
        api_payload = api.payload
        return signin (api_payload)
RemiDesgrange commented 4 years ago

Hi, you can use flask-CORS for this, which is simple and works like a charm.

jonatasoli commented 4 years ago

So my question remains, is there an annotation in the restx for cors, the idea would be to leave this part for the flask-cors or would it be put inside the restx?

For my solution here the flask-cors ended up solving it :)

RemiDesgrange commented 4 years ago

I think that the beauty of flask is it's diversity. You have a plugin for everything, OK it can clash, but it's not a full featured framework like django. For me, no need to add cors capabilities to restx, but that's my opinion :smile:

jonatasoli commented 4 years ago

No problem, I think it makes sense. As I had found this annotation I had this doubt, but beauty I already have that in mind :)