Phil Dreizen

Python Flask

I decided to learn flask for the purpose of implementing a RESTful API in Python. The two major choices seem to be Django and Flask. Flask is a lightweight option, which was more appealing to me for the flexibility that comes with that.

After doing the tutorial I do like it enough to try it out.

One thing I'm not liking from the tutorial is how a single function has to handle multiple methods (ie GET and POST), explicitly checking the request for which method is being used. It's hardly a deal-breaker.

I did briefly look at Flask-RESTful which addresses this by having each url map to a "resource" class which has methods that correspond to each HTTP method. So the class' "post()" method is mapped to a POST request. I think I prefer that, so I'll be looking at Flask-RESTful and its various forks (Flask-RESTplus, Flask-RESTx....and so on).

FYI: I'm currently most familiar with Java's Jersey framework for REST APIs.

BTW: Though Flask-RESTful's "resource" class is named the same as Jersey's "Resource" concept, I actually think vanilla Flask's Blueprint is closer.

tags: TIL, flask, python