Skip to content

sonampanwar4/Blogpost-with-fastapi

Repository files navigation

🚀 Blogpost with FastAPI

GitHub Workflow Status Python Version License

A powerful, async-ready 🌀 blog post API built with FastAPI, PostgreSQL, and JWT authentication. This project is designed for learning and real-world use, featuring robust testing, CI/CD integration, and modular architecture.


📚 Table of Contents


✨ Features

  • 🔐 JWT Authentication (OAuth2 Password Flow)
  • 🧵 Fully Async with SQLAlchemy 2.0
  • 🐘 PostgreSQL Database Integration
  • 🧪 Pytest-based Testing Suite
  • 🚦 Flake8 Linting
  • 🛠 Alembic for DB Migrations
  • 🔄 CI/CD with GitHub Actions
  • 📦 Modular FastAPI App Structure

⚙️ Requirements

  • ✅ Python 3.10+
  • ✅ PostgreSQL
  • ✅ Git

🚀 Getting Started

🔧 Clone the Repository

git clone https://github.com/spKnowTech/Blogpost-with-fastapi.git
cd Blogpost-with-fastapi

🧪 Create a Virtual Environment

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

📦 Install Dependencies

pip install -r requirements.txt

🧾 Environment Variables

Create a .env file in the root directory with the following content:

DB_HOSTNAME=localhost
DB_PORT=5432
DB_USERNAME=postgres
DB_PASSWORD=yourpassword
DB_NAME=blogdb
TEST_DB_NAME=blogdb_test
SECRET_KEY=your_secret_key
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=30
ALEMBIC_DATABASE_URL=postgresql://postgres:yourpassword@localhost:5432/blogdb

⚒️ Usage

🛠 Run Migrations

alembic upgrade head

🚀 Start Development Server

uvicorn blogpost:app --reload

📡 API Endpoints

🔐 Auth Routes

| Method | Path           | Description         |
| ------ | -------------- | ------------------- |
| POST   | `/auth/login`  | Login with JWT      |
| POST   | `/auth/signup` | Register a new user |

📝 Blog Routes

| Method | Path          | Description         |
| ------ | ------------- | ------------------- |
| GET    | `/blogs/`     | List all blog posts |
| POST   | `/blogs/`     | Create a new post   |
| GET    | `/blogs/{id}` | Get a post by ID    |
| PUT    | `/blogs/{id}` | Update a post       |
| DELETE | `/blogs/{id}` | Delete a post       |

🧪 Testing

Run unit tests:

pytest tests/ -v

Lint your code:

flake8 --verbose

CI/CD will automatically:

  • Spin up a PostgreSQL test container
  • Run flake8
  • Run all tests on every push

🗂 Project Structure

Blogpost-with-fastapi/
│
├── alembic/              # Alembic migration scripts
├── routers/              # API routers (auth, blogs)
├── tests/                # Unit and integration tests
├── blogpost.py           # Main FastAPI app instance
├── database.py           # DB engine & session
├── models.py             # SQLAlchemy ORM models
├── oauth2.py             # Token creation/validation
├── schemas.py            # Pydantic request/response models
├── settings.py           # App settings from .env
├── utils.py              # Password hashing, helpers
└── requirements.txt

🤝 Contributing

Contributions are welcome! 🎉

  1. Fork the repo
  2. Create a new branch
  3. Commit your changes
  4. Open a PR with a clear explanation

📄 License

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

Made with ❤️ by spKnowTech

Next Step: Copy this into a new file named README.md in the root of your GitHub repo.

Let me know if you want badges for test coverage, Docker instructions, or deployment tips!

About

The purpose of blog posting app is to focus on learning use of build Async APIs by FastAPI with JWT Authentication, PostgreSQL database, and tests for APIs endpoints.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors