Skip to content

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

License

Notifications You must be signed in to change notification settings

cyxabima/fastapi-social-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🌐 FastAPI Social Media REST API

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.


🚀 Features

📄 Posts

  • GET /api/v1/posts — Retrieve all posts
  • GET /api/v1/post/{id} — Retrieve a single post by ID
  • POST /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)

👥 Users

  • POST /api/v1/user — Register a new user
  • GET /api/v1/user/{id} — Retrieve user information by ID

🔐 Authentication

  • POST /api/v1/login — Login and receive a JWT access token

👍 Votes

  • POST /api/v1/vote — Like or unlike a post (requires login)

🧰 Tech Stack

  • 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

📁 Project Structure

.
├── 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

⚙️ Setup Instructions

1️⃣ Clone the Repository

git clone https://github.com/cyxabima/fastapi-social-api
cd fastapi-social-api

2️⃣ Create Virtual Environment

python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

3️⃣ Install Dependencies

pip install -r requirements.txt

4️⃣ Configure Environment Variables

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

5️⃣ Run Database Migrations

alembic upgrade head

6️⃣ Start the API Server

uvicorn app.main:app --reload

🔐 Authentication

  • Obtain a JWT token from /api/v1/login
  • Use the token as a Bearer token in the Authorization header to access protected routes

📌 Future Enhancements

  • 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)

📃 License

This project is licensed under the MIT License. See the LICENSE file for more details.


About

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published