Feature #1386
closedAPI: Flask restful framework
Description
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
Installation
# apt install python3-flask-restful
Updated by Bernhard Koschiček-Krombholz about 4 years ago
- Related to Feature #1274: API: Automatic documentation for code added
Updated by Bernhard Koschiček-Krombholz about 4 years ago
- Related to Feature #1184: API: add additional output format RDFS added
Updated by Bernhard Koschiček-Krombholz about 4 years ago
- Related to Question #1382: API: Other jsonld mappings beside linked-places added
Updated by Bernhard Koschiček-Krombholz about 4 years 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 Bernhard Koschiček-Krombholz about 4 years ago
- Related to Feature #1390: API: Swagger file in OpenAtlas repository added
Updated by Alexander Watzinger about 4 years 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/
Updated by Bernhard Koschiček-Krombholz about 4 years ago
As usual, you save the day or night. Thank you! This looks very promising.
Updated by Bernhard Koschiček-Krombholz almost 4 years ago
- Status changed from Assigned to In Progress
Basically it is done and in develop branch. After a final code review with Alex and maybe a look over from Christoph, this ticket can be closed.
Updated by Bernhard Koschiček-Krombholz almost 4 years ago
- Status changed from In Progress to Closed
- Target version changed from 208 to 5.7.0
Updated by Alexander Watzinger almost 4 years ago
- Subject changed from API: Implement flask restful framework to API: Flask restful framework