I got the impression that it was good to know Flask on pyconjp etc. in 2012 and it was a micro framework and could be used to make a small service. After a while, there was talk of creating a REST API using RDB, but I will write my impressions that I had a hard time and failed using Flask.
Easy to use MethodView class Creating a REST API was really easy because if you create a class that inherits the MethodView class for each entry point and define the get / post / put / delete method, you can handle GET / POST / PUT / DELETE requests respectively.
Do not use POST to update resources For API users, I made the specification to accept updates by POST, but when I started implementing it, I thought it would be troublesome. This method wasn't very suitable for using SQLAlchemy as an ORM. If you create the REAST API with POST / PUT / DELETE / GET, both developers and users will be happy.
Flask-SQLAlchemy is hard to use. Flask-SQLAlchemy is also difficult to use beyond the sample because there are no examples of use that can be used as a reference. It's more flexible to use plain SQLAlchemy, and the code can be used for other batch processing, so I think it's better not to use extensions as much as possible.
Not many Blueprint documentation When the code grows after a while, I feel that one script is too big and I want to use a module called Blueprint that divides the code, but this also has no documentation and I can use it by reading the code It takes time and effort to get it done. I gave up the division using Blueprint and forced it into one file.
It is difficult to understand how to test Regarding 3,4,5, I think it results in the lack of documentation / sample code in general. Flask has few usage examples, so I hope that the amount of information in this section will increase in the future.
Cannot receive parameters in DELETE request
I didn't notice it until I started implementing it, so please be aware that if you adopt a specification that changes resources at the timing of deletion, you will be in trouble later.
Addition
Properly, I got the parameters with request.args ["hoge"] in the DELETE request as below.
% curl -X DELETE "http://localhost:9999/users/100?hoge=100"
As for SQLAlchemy, I tried using it with the knowledge that I had used it for a while, so it may have been off the mark. I wrote it because I might be addicted to making something with Flask + SQLAlchemy as a beginner.
I had a lot of experience with Flask in 2012, so in 2013 I'll try to add new experiences with Django, which has more features than Flask.
I look forward to working with you again this year.
PyCon JP 2012 hands-on session / Web application implementation and programming tools with Flask
Recommended Posts