A simple and professional Blog API built with FastAPI, SQLite, and Pydantic. This project demonstrates how to create, list, and delete blog posts while applying data validation, path & query parameters, and database persistence.
- 📝 Create Blog Post – Add new posts with title & content
- 📖 List Blog Posts – Fetch all posts with pagination (query params)
- ❌ Delete Blog Post – Remove a post by its ID
- ⚡ FastAPI for modern, high-performance APIs
- ✅ Pydantic Models for request & response validation
- 🗄️ SQLite database for data persistence
- Python 3.10+
- FastAPI – Web framework
- SQLite – Database
- SQLAlchemy – ORM
- Pydantic – Data validation
- Uvicorn – ASGI server
blog_api/
│── main.py # Entry point of the API
│── database.py # DB connection setup
│── models.py # SQLAlchemy models
│── schemas.py # Pydantic models
│── crud.py # Database operations (create, read, delete)
-
Clone the repository
git clone https://github.com/your-username/blog-api.git cd blog-api
-
Create virtual environment
python -m venv venv source venv/bin/activate # On Linux/Mac venv\Scripts\activate # On Windows
-
Install dependencies
pip install -r requirements.txt
-
Run the API
uvicorn blog_api.main:app --reload
POST /blogs/
Request body:
{
"title": "My First Blog",
"content": "Hello, this is my first post!"
}
GET /blogs/?skip=0&limit=10
skip
→ number of records to skip (default: 0)limit
→ number of records to return (default: 10)
Response:
[
{
"id": 1,
"title": "My First Blog",
"content": "Hello, this is my first post!"
}
]
DELETE /blogs/{blog_id}
Example:
DELETE /blogs/1
Response:
{
"message": "Blog 1 deleted successfully"
}
Once the server is running, you can explore the interactive docs:
- Swagger UI → http://127.0.0.1:8000/docs
- ReDoc → http://127.0.0.1:8000/redoc
- 🔒 Add authentication & authorization (JWT)
- 📝 Update blog posts (PUT/PATCH)
- 🔍 Search & filter blogs
- 📊 Add tags & categories
Contributions are welcome! Feel free to fork the repo and submit a pull request.
This project is licensed under the MIT License.
Would you like me to also generate a requirements.txt
file so that this README setup works immediately when someone clones your repo?