Exploring FastAPI
- Users can write Posts
- Users can like/dislike posts
- Basic Password Oauth2 Login authentication using JWT
1. Users with attributes email, password, phone_number
2. Posts with attributes title and content, published, owner_id (who created this post)
3. Votes with attribute post_id, user_id
GET /posts /posts/id /users/id
DELETE /posts/id
POST /posts /users /login /vote
PUT /posts/id
Added tests for users, votes and posts
It covers following technical topics in a single app:
-
Database modeling with postgres & sqlalchemy check -> database.py models.py schema.py
-
REST API for CRUD Operations on database with FastAPI. check -> app.py and routers/post.py, routers/user.py, routers/vote.py
-
Automated unit testing for test driven development (TTD) with pytest (check-> test/ directory)
-
DataBase Migration Experience with alembic
-
Authorization with Auth0 (check routers/auth.py)
-
Deployment on Heroku / ubuntu with github actions with CI/CD
Follow instructions to install the latest version of python for your platform in the python docs
We recommend working within a virtual environment whenever using Python for projects. This keeps your dependencies for each project separate and organaized. Instructions for setting up a virual enviornment for your platform can be found in the python docs
Example in my code :
python3 -m venv env source env/bin/activate
Once you have your virtual environment setup and running, install dependencies
pip install -r requirements.txt
This will install all of the required packages we selected within the requirements.txt
file.
-
FastAPI is backend microservices framework. FastAPI is required to handle requests and responses.
-
SQLAlchemy is the Python SQL toolkit and ORM we'll use handle the lightweight sqlite database. You'll primarily work in app.py and can reference models.py.
Also set the following environmental variable for Auth0
# You can replace following with your details This is my details and this token can be useful for running and testing my app, but this token might expired
export PG_DATABASE_HOST=<YOUR INPUT>
export PG_DATABASE_PORT=5432
export PG_DATABASE_PASSWORD=<YOUR INPUT>
export PG_DATABASE_USERNAME=<YOUR INPUT>
export PG_DATABASE_NAME=<YOUR INPUT>
export JWT_SECRET_KEY=<YOUR INPUT>
export JWT_ALGORITHM=HS256
export JWT_TOKEN_EXPIRED_MINUTES=60
please create database according to setting given or you can change accordingly
- Other Deployment instructions are added in workflows, Procfile, gunicorn.service, nginx files, please see in repository