FastAPI (API) Server
Simple FastAPI Starter enhanced with JWT authentication, OAuth via GitHub, SqlAlchemy, SQLite persistence and deployment scripts via Docker - Actively supported by App-Generator.
👉 For more FastAPI Resources please access:
Product Roadmap &
Features:
| Status | Item | info |
|---|---|---|
| ✅ | Up-to-date Dependencies | - |
| ✅ | JWT Authentication |
(login, logout, register) via oauth2 |
| ✅ | OAuth | via GitHub` |
| ✅ | Persistence | SQLite, MySql |
| ✅ | Docker | - |
| ✅ | Unitary tests | minimal suite |
Get the code
$ git clone https://github.com/app-generator/api-server-fastapi.git
$ cd api-server-fastapiStart the app in Docker
$ docker-compose up --build Note: The env.sample file will be used to set the environment variables for the docker container. Make sure to set them as needed.
The API server will start using the PORT 5000.
Step #1 - Clone the project
$ git clone https://github.com/app-generator/api-server-flask.git
$ cd api-server-flaskStep #2 - create virtual environment using python3 and activate it (keep it outside our project directory)
$ # Virtualenv modules installation (Unix based systems)
$ virtualenv env
$ source env/bin/activate
$
$ # Virtualenv modules installation (Windows based systems)
$ # virtualenv env
$ # .\env\Scripts\activateStep #3 - Install dependencies in virtualenv
$ pip install -r requirements.txtStep #5 - Create a new
.envfile using sampleenv.sample
The meaning of each variable can be found below:
DEBUG: ifTruethe app runs in develoment mode- For production value
Falseshould be used
- For production value
SECRET_KEY: used in assets managementGITHUB_CLIENT_ID: For GitHub social loginGITHUB_SECRET_KEY: For GitHub social loginDATABASE_HOSTNAME: For Mysql databseDATABASE_PORT: For Mysql databseDATABASE_PASSWORD: For Mysql databseDATABASE_NAME: For Mysql databseDATABASE_USERNAME: For Mysql databseALGORITHM: For JWT TokensACCESS_TOKEN_EXPIRE_MINUTES: For JWT Tokens
Step #6 - start test APIs server at
localhost:5000
$ uvicorn src.app:appUse the API via POSTMAN or Swagger Dashboard.
api-server-flask/
├── src
├── helpers
├── database.py
└── utils.py
├── routers
├── users.py
│ ├── __init__.py
│ ├── app.py
│ ├── config.py
│ ├── models.py
│ ├── oatuh2.py
│ └── schemas.py
├── tests
├── __init__.py
├── conftest.py
├── database.py
└── test_users.py
├── Dockerfile
├── docker-compose.yaml
├── README.md
├── requirements.txt
├── run.pyFor a fast set up, use this POSTMAN file: api_sample
Register -
api/users/register(POST request)
POST api/users/register
Content-Type: application/json
{
"username":"test",
"password":"pass",
"email":"test@appseed.us"
}
Login -
api/users/login(POST request)
POST /api/users/login
Content-Type: application/json
{
"password":"pass",
"email":"test@appseed.us"
}
Logout -
api/users/logout(POST request)
POST api/users/logout
Content-Type: application/json
authorization: JWT_TOKEN (returned by Login request)
{
"token":"JWT_TOKEN"
}
Run tests using pytest tests.py
FastAPI (API) Server - Open-source eCommerce Starter provided by App-Generator.
