简体   繁体   中英

Flask MethodView vs Flask-Restful Resource

What is difference between MethodView and Resource?

It implements API by flask-restful:

class API(Resource):
    decorators = [...,]

    def get(self):
        # do something
    def post(self):
        # do something
    def put(self):
        # do something
    def delete(self):
        # do something

Actually, it can be replaced by flask:

class API(MethodView):
    decorators = [...,]

    def get(self):
        # do something
    def post(self):
        # do something
    def put(self):
        # do something
    def delete(self):
        # do something

I think Flask has offered enough about establishing Restful API. I can't find flask-restful can do more something than flask because they have CRUD methods and decoraters in class of mechanism in the same. What is special about flask-restful?

I am evaluating whether or not Flask-Restful is really necessary for me. Please tell me, thanks.

I was wondering same thing and according to this post Resource is inherited from Methodview ( http://blog.miguelgrinberg.com/post/designing-a-restful-api-using-flask-restful ). Article describes also added value to compared to plain Flask like "Flask-RESTful provides a much better way to handle this with the RequestParser class. This class works in a similar way as argparse for command line arguments." And much of work with your API is still something to do with authentication and security like parameters/data checking.

Thx to Miguel to excellent blog. I'm using flask-restful because it seems to be quite mature.

If your need is very tiny, then I think you can use flask only approach.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM