This is a simple RESTful API for a social networking application built within FastAPI. It allows users to authenticate, register, create, edit, delete, and view posts, as well as like or dislike other users' posts.
To get started with the API, follow these instructions.
Make sure you have the following software installed on your machine:
- preferable OS - Linux
- Docker
- Docker Compose
- Clone the repository:
git clone {<url>}
-
Create an
.env
file based on your environment and set the required environment variables. -
Build and run the Docker containers
docker-compose build --no-cache
docker-compose up
These commands will build the FastAPI application container, PostgreSQL database container, and Redis cache container.
- Wait for the containers to start up. You can check the logs to monitor the progress:
docker-compose logs -f
-
Once the containers are up and running, you can access the API documentation by visiting
http://<host>:<port>/docs
in your web browser. -
To run unit tests, use the following command:
python -m pytest -s -rP
To authenticate or register a user, you can use the following endpoints:
POST /register
- Register a new userPOST /login
- Authenticate and retrieve a JWT token
To manage posts, you can use the following endpoints:
GET /posts/{post_id}
- Get a specific post by IDPOST /posts
- Create a new postPUT /posts/{post_id}
- Update a postDELETE /posts/{post_id}
- Delete a post
To like or dislike a post, you can use the following endpoints:
POST /posts/{post_id}/like
- Like a postPOST /posts/{post_id}/dislike
- Dislike a post
Please note that you cannot like or dislike your own posts.
- FastAPI - Web framework for building the API
- PostgreSQL - Relational database for storing user and post data
- Redis - In-memory data store for caching
- Docker - Containerization platform for easy deployment
- Docker-Compose - Tool for defining and running multi-container Docker applications