Simple REST API social network with FastAPI
- There should be some form of authentication and registration (JWT, Oauth, Oauth 2.0, etc..)
- As a user I need to be able to signup and login
- As a user I need to be able to create, edit, delete and view posts
- As a user I can like or dislike other users’ posts but not my own
- The API needs a UI Documentation (Swagger/ReDoc)
First you need clone git repo using
git clone https://github.com/IsThatASkyline/social_network.git
cd social_network
Set environment variables in .docker-compose.env (you can leave variables and it will work) and run
docker-compose up --build
You need run PostgreSQL database by yourself, then set variables in .env file, then run
pip install -r requirements.txt
alembic revision --autogenerate -m 'Init'
alembic upgrade head
uvicorn src.main:app --reload
To see docs visit
http://localhost:8000/docs
Tests are in 'tests' folder, you can run them
First you need to create database for test (TEST_POSTGRES_DB in .docker-compose.env)
- Check CONTAINER_ID of running postgres:
docker ps
- Connect to container using
docker exec -it CONTAINER_ID bash
- Connect to Postgres
psql -U postgres
- Create database for tests
CREATE DATABASE test_db;
- After creating database you can check CONTAINER_ID of app and connect to it:
docker ps
docker exec -it CONTAINER_ID bash
- And run tests
pytest -v -s tests/
pytest -v -s tests/
- Make special init file to create databases from docker-compose up and not to create them manually https://stackoverflow.com/questions/49024243/how-do-i-create-a-database-within-a-docker-container-using-only-the-docker-compo
- Use an in-memory DB for storing post likes and dislikes (As a cache, that gets updated whenever new likes and dislikes get added) https://github.com/long2ice/fastapi-cache
- Use emailhunter.co for verifying email existence on registration (or just background tasks (Celery for example))
- Use https://clearbit.com/platform/enrichment for getting additional data for the user on signup (or u can create OneToOne table 'user_profile' and store additional data there)