Flask-RestX
This tool aims to provide a secure, production-ready API via Flask-RestX
using the developer's minimum amount of code.
For newcomers, Flask is a leading backend framework used to code from simple websites and API's to complex eCommerce solutions.
Flask-RestX is a popular library for developing secure API services using Flask.
Clone/Download Sources
$ git clone https://github.com/app-generator/flask-dynamic-api.git
$ cd flask-dynamic-api
Install Modules
$ virtualenv env
$ source env/bin/activate
$ pip install -r requirements.txt
Update ENV
$ export FLASK_APP=run.py
Migrate DB
$ flask db init # INIT needs to be executed only once
$ flask db migrate # Needs to be executed at each DB Schema Update
$ flask db upgrade # Needs to be executed at each DB Schema Update
Start the project
$ flask run
The Dynamic API tool aims to enable a secured API service on top of any Flask codebase with a minimum effort. Here are the steps:
Define a new model
in the project (an old one can be also used)Execute the database migration
to create/update the associated tablesUpdate the configuration
to enable the Dynamic API over the modelStart the app
Dynamic API Service
For instance, if the new model managed by the Dynamic API is called books, the associate API is exposed at /api/books/
Status | Item | info |
---|---|---|
β | New Models Definition in apps/models |
- |
β | The app is saved in apps/dyn_api |
- |
β | Models enabled in apps/config.py via DYNAMIC_API variable |
- |
β | The project exposes automatically a CRUD API over the new model | - |
β | Path of the service: /api/books/ |
In case the new model is Books |
β | The API is powered via Flask-RestX using best practices | - |
Before using the API, the user must make a request to the `/login' endpoint and send his username and password.:
POST /login
{
"username": "my_username",
"password": "my_password"
}
The server returns a token if approved.
{
"token": "RETURNED_TOKEN"
}
To use the features, the user must add a key and value to the headers.
headers of requests:
{
...
"Authorization": "token RETURNED_TOKEN"
...
}
Note: token will be expired after 24 hours.
Flask Dynamic API via Flask-RestX
- Developer tool provided by AppSeed