Reputation: 1057
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.
Upvotes: 13
Views: 4821
Reputation: 428
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.
Upvotes: 5