API: Flask restful framework
As discussed in the OpenAtlas development session 10th October, now is a good time to deploy a framework for a standardized output (header, status codes, other formats).
We will look into flask-restful
# apt install python3-flask-restful
Updated by Bernhard Koschiček-Krombholz 11 months ago
I looked into flask-restful. It is not complicated and quite intuitive. Right now, our API can quite the same but flask-restful is way easier to read.
One major problem I found is, that the flask-restful package alone is not compatable with swagger automatic annotation. For this we need another package named flask-restful-swagger which is not a Debian package. We also can you flask-restx which has the swagger annotation included, but again, no Debian package.
I will complete the transformation to restful anyway, because it is easier to read and maybe I find new way to make the API request faster. How we cope with swagger, besides manual manipulation, I don't know.
Updated by Alexander Watzinger 11 months ago
I'm no expert there but what about python3-flasgger? It's a Debian package and sounds promising:
Flasgger is a Flask extension to extract OpenAPI-Specification from all Flask views registered in your API. It also comes with SwaggerUI embedded so you can access http://localhost:5000/apidocs and visualize and interact with your API resources. It also provides validation of the incoming data, using the same specification it can validates if the data received as a POST, PUT, PATCH is valid against the schema defined using YAML, Python dictionaries or Marshmallow Schemas. Flasgger can work with simple function views or MethodViews using docstring as specification, or using @swag_from decorator to get specification from YAML or dict and also provides SwaggerView which can use Marshmallow Schemas as specification.
This article shows an example how to use it: https://kanoki.org/2020/07/18/python-api-documentation-using-flask-swagger/