Skip to content

✍️ 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.

Notifications You must be signed in to change notification settings

engripaye/blog-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


✍️ Blog API (FastAPI + SQLite + Pydantic)

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.


🚀 Features

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

🛠️ Tech Stack

  • Python 3.10+
  • FastAPI – Web framework
  • SQLite – Database
  • SQLAlchemy – ORM
  • Pydantic – Data validation
  • Uvicorn – ASGI server

📂 Project Structure

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)

⚙️ Installation & Setup

  1. Clone the repository

    git clone https://github.com/your-username/blog-api.git
    cd blog-api
  2. Create virtual environment

    python -m venv venv
    source venv/bin/activate   # On Linux/Mac
    venv\Scripts\activate      # On Windows
  3. Install dependencies

    pip install -r requirements.txt
  4. Run the API

    uvicorn blog_api.main:app --reload

🔗 API Endpoints

➕ Create Blog Post

POST /blogs/ Request body:

{
  "title": "My First Blog",
  "content": "Hello, this is my first post!"
}

📖 List All Blog Posts

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 Blog Post

DELETE /blogs/{blog_id} Example:

DELETE /blogs/1

Response:

{
  "message": "Blog 1 deleted successfully"
}

📸 API Documentation

Once the server is running, you can explore the interactive docs:


📌 Future Improvements

  • 🔒 Add authentication & authorization (JWT)
  • 📝 Update blog posts (PUT/PATCH)
  • 🔍 Search & filter blogs
  • 📊 Add tags & categories

🤝 Contributing

Contributions are welcome! Feel free to fork the repo and submit a pull request.


📜 License

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?

About

✍️ 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.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages