A modern, secure micro-blogging API built with FastAPI
π The API is LIVE here, you are more than welcome to test it out π
π Here's the Swagger Documentations by the way. π
Bog is a straightforward yet powerful FastAPI backend for a micro-blogging social media platform. It provides all the essential features you'd expect from a modern social platform: user registration, secure authentication, post creation and management, social following, post likes, and personalized feeds.
- π Secure JWT Authentication - Token-based auth with bcrypt password hashing
- π₯ User Management - Registration, profiles, and user discovery
- π Post System - Create, update, delete, and manage blog posts
- β€οΈ Social Interactions - Like/unlike posts and follow/unfollow users
- π± Feed System - Discover users and view user-specific post feeds
- π Fast & Modern - Built with FastAPI for high performance
- π³ Docker Ready - Containerized for easy deployment
- π Auto-Generated Docs - Interactive API documentation with Swagger UI
- Framework: FastAPI
- Database: SQLite with SQLAlchemy ORM
- Authentication: JWT tokens with passlib (bcrypt)
- Validation: Pydantic models
- Containerization: Docker & Docker Compose
- Documentation: Automatic OpenAPI/Swagger docs
- Python 3.11+
- Git
-
Clone the Repository
git clone https://github.com/TheRootDaemon/bog.git cd bog
-
Create Virtual Environment
python -m venv venv # On Windows venv\Scripts\activate # On macOS/Linux source venv/bin/activate
-
Install Dependencies
pip install -r requirements.txt
-
Run the Application
uvicorn app.main:app --reload
-
Access the API
- API Server: http://localhost:8000
- Interactive Docs: http://localhost:8000/docs
- Alternative Docs: http://localhost:8000/redoc
# Clone and navigate to project
git clone https://github.com/TheRootDaemon/bog.git
cd bog
# Build and run with Docker Compose
docker-compose up -d
# View logs
docker-compose logs -f
# Stop the application
docker-compose down
# Build the image
docker build -t bog-api .
# Run the container
docker run -d -p 10000:10000 --name bog bog-api
The API will be available at http://localhost:10000
Method | Endpoint | Description | Auth Required |
---|---|---|---|
POST |
/auth/token |
Login and get JWT token | β |
Method | Endpoint | Description | Auth Required |
---|---|---|---|
POST |
/users |
Register a new user | β |
POST |
/users/{user_id}/follow |
Follow a user | β |
DELETE |
/users/{user_id}/unfollow |
Unfollow a user | β |
Method | Endpoint | Description | Auth Required |
---|---|---|---|
POST |
/posts |
Create a new post | β |
PUT |
/posts/{post_id} |
Update your post | β |
DELETE |
/posts/{post_id} |
Delete your post | β |
POST |
/posts/{post_id}/like |
Like a post | β |
DELETE |
/posts/{post_id}/like |
Unlike a post | β |
Method | Endpoint | Description | Auth Required |
---|---|---|---|
GET |
/feed |
Get random users for discovery | β |
GET |
/feed/{username} |
Get posts by username | β |
Method | Endpoint | Description | Auth Required |
---|---|---|---|
GET |
/ |
API health check | β |
GET |
/user |
Get current user info | β |
curl -X POST "http://localhost:8000/users" \
-H "Content-Type: application/json" \
-d '{
"username": "johndoe",
"email": "john@example.com",
"gender": "male",
"password": "securepassword123"
}'
curl -X POST "http://localhost:8000/auth/token" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "username=johndoe&password=securepassword123"
curl -X POST "http://localhost:8000/posts" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
-d '{
"title": "My First Post",
"content": "Hello, Bog community! This is my first post."
}'
curl -X POST "http://localhost:8000/users/2/follow" \
-H "Authorization: Bearer YOUR_JWT_TOKEN"
curl -X POST "http://localhost:8000/posts/1/like" \
-H "Authorization: Bearer YOUR_JWT_TOKEN"
curl -X GET "http://localhost:8000/feed/johndoe"
bog/
βββ app/
β βββ __init__.py
β βββ main.py # FastAPI app initialization
β βββ database.py # Database configuration
β βββ models.py # SQLAlchemy ORM models
β βββ schemas.py # Pydantic request/response models
β βββ routes/
β βββ __init__.py
β βββ auth.py # Authentication endpoints
β βββ registerUser.py # User registration
β βββ follow.py # Follow/unfollow functionality
β βββ posts.py # Post management
β βββ feed.py # Feed endpoints
βββ blog.db # SQLite database file
βββ requirements.txt # Python dependencies
βββ dockerfile # Docker configuration
βββ compose.yml # Docker Compose configuration
βββ README.md # This file
- Register: Create a new user account via
/users
- Login: Get JWT token via
/auth/token
- Authenticate: Include token in
Authorization: Bearer <token>
header - Access: Use token to access protected endpoints
id
(Primary Key)username
(Unique)email
gender
password
(Hashed)
id
(Primary Key)author
(Foreign Key to Users)title
content
- Follow: Many-to-many relationship between users
- Likes: Many-to-many relationship between users and posts
Code | Description |
---|---|
200 |
Success |
201 |
Created |
400 |
Bad Request |
401 |
Unauthorized |
404 |
Not Found |
422 |
Validation Error |
Visit the interactive API documentation at:
- Live Demo: https://bog-d62w.onrender.com/docs
- Local: http://localhost:8000/docs (when running locally)
The Swagger UI provides a complete interface to test all endpoints with proper authentication.
Currently, the application uses default configurations. For production deployment, consider setting:
SECRET_KEY
: JWT signing secret (currently hardcoded)DATABASE_URL
: Database connection stringACCESS_TOKEN_EXPIRE_MINUTES
: Token expiration time
The application uses SQLite by default with the database file blog.db
. The database is automatically created when you first run the application.
-
Security:
- Change the hardcoded
SECRET_KEY
inauth.py
- Use environment variables for sensitive data
- Enable HTTPS in production
- Change the hardcoded
-
Database:
- Consider PostgreSQL for production
- Set up proper backups
-
Performance:
- Use a production ASGI server like Gunicorn with Uvicorn workers
- Set up proper logging
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
- Live API: https://bog-d62w.onrender.com/docs
- Repository: https://github.com/TheRootDaemon/bog
- FastAPI Documentation: https://fastapi.tiangolo.com/
- SQLAlchemy Documentation: https://docs.sqlalchemy.org/