app-generator / flask-dynamic-api

Flask Dynamic API - Developer Tool | AppSeed
https://appseed.us
Other
3 stars 0 forks source link
api appseed dynamic-programming flask open-source

Flask Dynamic API via 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.

Video Presentation

https://user-images.githubusercontent.com/51070104/194328733-3bdf8c70-f765-4168-983d-2a51e276239b.mp4


Manual Build

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


How it works

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:

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 -


API Permissions

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