This is a RESTful API for a Social Media Application built using FastAPI and PostgreSQL. It supports core social media features such as user registration, login, post creation, and voting (like/dislike). JWT-based authentication ensures secure access to protected routes.
GET /api/v1/posts
— Retrieve all postsGET /api/v1/post/{id}
— Retrieve a single post by IDPOST /api/v1/post
— Create a new post (requires login)PUT /api/v1/post/{id}
— Update an existing post (requires login and ownership)DELETE /api/v1/post/{id}
— Delete a post (requires login and ownership)
POST /api/v1/user
— Register a new userGET /api/v1/user/{id}
— Retrieve user information by ID
POST /api/v1/login
— Login and receive a JWT access token
POST /api/v1/vote
— Like or unlike a post (requires login)
- FastAPI – high-performance Python framework for APIs
- PostgreSQL – relational database backend
- SQLAlchemy – ORM for database interaction
- Alembic – database migrations
- Pydantic – data validation
- JWT – secure token-based authentication
- Swagger UI – built-in interactive API docs
.
├── app/
│ ├── main.py
│ ├── models.py
│ ├── schemas.py
│ ├── database.py
│ ├── oauth2.py
│ ├── routers/
│ │ ├── post.py
│ │ ├── user.py
│ │ ├── auth.py
│ │ └── vote.py
│ └── utils.py
├── alembic/
├── requirements.txt
├── .env
├── README.md
├── LICENSE
git clone https://github.com/cyxabima/fastapi-social-api
cd fastapi-social-api
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt
Create a .env
file with:
DATABASE_URL=postgresql://username:password@localhost:5432/dbname
SECRET_KEY=your_secret_key
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=30
alembic upgrade head
uvicorn app.main:app --reload
- Swagger Docs: http://localhost:8000/docs
- Redoc Docs: http://localhost:8000/redoc
- Obtain a JWT token from
/api/v1/login
- Use the token as a Bearer token in the
Authorization
header to access protected routes
- Add user profiles and avatars
- Commenting system
- Social following/followers
- Pagination and filtering
- Notification system
- Integration with a real frontend (e.g., React or Next.js)
This project is licensed under the MIT License. See the LICENSE
file for more details.