|
1 | 1 | --- |
2 | | -sidebar_position: 4 |
3 | | -description: Developer Tool - Dynamic API via Flask-RestX |
| 2 | +title: Flask Dynamic API - Open-Source tool provided by AppSeed |
| 3 | +sidebar_label: Flask Dynamic API |
4 | 4 | --- |
5 | 5 |
|
6 | 6 | # Flask Dynamic API |
7 | 7 |
|
8 | | -@Todo |
| 8 | +This tool aims to provide a secure, `production-ready API via Flask-RestX` using the developer's minimum amount of code. |
| 9 | +For newcomers, **Flask** is a leading backend framework used to code from simple websites and API's to complex eCommerce solutions. |
| 10 | + |
| 11 | +**Flask-RestX** is a popular library for developing secure API services using Flask. |
| 12 | + |
| 13 | +- 👉 Free [support](https://appseed.us/support/) via Email and [Discord](https://discord.gg/fZC6hup) |
| 14 | +- 👉 More [Developer Tools](https://appseed.us/developer-tools/) - provided by AppSeed |
| 15 | + |
| 16 | +## ✅ Video Presentation |
| 17 | + |
| 18 | +<YoutubeEmbed url="https://user-images.githubusercontent.com/51070104/194328733-3bdf8c70-f765-4168-983d-2a51e276239b.mp4" title="Flask Dynamic API - Open-Source tool provided by AppSeed" /> |
| 19 | + |
| 20 | + |
| 21 | +## ✅ Manual Build |
| 22 | + |
| 23 | +> Clone/Download Sources |
| 24 | +
|
| 25 | +```bash |
| 26 | +$ git clone https://github.com/app-generator/flask-dynamic-api.git |
| 27 | +$ cd flask-dynamic-api |
| 28 | +``` |
| 29 | + |
| 30 | +> Install Modules |
| 31 | +
|
| 32 | +```bash |
| 33 | +$ virtualenv env |
| 34 | +$ source env/bin/activate |
| 35 | +$ pip install -r requirements.txt |
| 36 | +``` |
| 37 | + |
| 38 | +> Update ENV |
| 39 | +
|
| 40 | +```bash |
| 41 | +$ export FLASK_APP=run.py |
| 42 | +``` |
| 43 | + |
| 44 | +> Migrate DB |
| 45 | +
|
| 46 | +```bash |
| 47 | +$ flask db init # INIT needs to be executed only once |
| 48 | +$ flask db migrate # Needs to be executed at each DB Schema Update |
| 49 | +$ flask db upgrade # Needs to be executed at each DB Schema Update |
| 50 | +``` |
| 51 | + |
| 52 | +> Start the project |
| 53 | +
|
| 54 | +```bash |
| 55 | +$ flask run |
| 56 | +``` |
| 57 | + |
| 58 | +## ✅ How it works |
| 59 | + |
| 60 | +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: |
| 61 | + |
| 62 | +- `Define a new model` in the project (an old one can be also used) |
| 63 | +- `Execute the database migration` to create/update the associated tables |
| 64 | +- `Update the configuration` to enable the Dynamic API over the model |
| 65 | +- `Start the app` |
| 66 | +- Access the `Dynamic API Service` |
| 67 | + |
| 68 | +For instance, if the new model managed by the Dynamic API is called books, the associate API is exposed at /api/books/ |
| 69 | + |
| 70 | +<br /> |
| 71 | + |
| 72 | +| Status | Item | info | |
| 73 | +| --- | --- | --- | |
| 74 | +| ✅ | New Models Definition in `apps/models` | - | |
| 75 | +| ✅ | The app is saved in `apps/dyn_api` | - | |
| 76 | +| ✅ | Models enabled in `apps/config.py` via `DYNAMIC_API` variable | - | |
| 77 | +| ✅ | The project exposes automatically a CRUD API over the new model | - | |
| 78 | +| ✅ | Path of the service: `/api/books/` | In case the new model is `Books` | |
| 79 | +| ✅ | The API is powered via Flask-RestX using best practices | - | |
| 80 | + |
| 81 | + |
| 82 | +## ✅ API Permissions |
| 83 | + |
| 84 | +Before using the API, the user must make a request to the `/login' endpoint and send his username and password.: |
| 85 | + |
| 86 | +```json |
| 87 | +POST /login |
| 88 | +{ |
| 89 | + "username": "my_username", |
| 90 | + "password": "my_password" |
| 91 | +} |
| 92 | +``` |
| 93 | + |
| 94 | +The server returns a token if approved. |
| 95 | + |
| 96 | +```json |
| 97 | +{ |
| 98 | + "token": "RETURNED_TOKEN" |
| 99 | +} |
| 100 | +``` |
| 101 | + |
| 102 | +To use the features, the user must add a key and value to the headers. |
| 103 | + |
| 104 | +headers of requests: |
| 105 | +```json |
| 106 | +{ |
| 107 | + ... |
| 108 | + "Authorization": "token RETURNED_TOKEN" |
| 109 | + ... |
| 110 | +} |
| 111 | +``` |
| 112 | +**Note:** token will be expired after 24 hours. |
| 113 | + |
| 114 | +## ✅ Resources |
| 115 | + |
| 116 | +- 👉 Access [AppSeed](https://appseed.us/) and start your next project |
| 117 | +- 👉 [Deploy Projects on Aws, Azure and Digital Ocean](https://www.docs.deploypro.dev/) via **DeployPRO** |
| 118 | +- 👉 Create an amazing landing page with [Simpllo, an open-source site builder](https://www.simpllo.com/) |
0 commit comments