Skip to content

Latest commit

 

History

History
122 lines (88 loc) · 3.02 KB

README.md

File metadata and controls

122 lines (88 loc) · 3.02 KB

FastAPI Blog Application with MySQL

A comprehensive RESTful API blog application built with FastAPI and MySQL, featuring user authentication, blog post management, and secure data handling.

Features

  • 🔐 JWT Authentication
  • 📝 Blog Post CRUD Operations
  • 🗄️ MySQL Database Integration
  • 🚀 FastAPI Framework
  • 🔄 RESTful API Architecture
  • 🛡️ Secure Password Hashing

Tech Stack

  • FastAPI: Modern Python web framework for building APIs
  • MySQL: Relational database for persistent storage
  • SQLAlchemy: SQL toolkit and ORM
  • Alembic: Database migration tool
  • PyJWT: JSON Web Token implementation
  • Python 3.8+: Core programming language

Installation

  1. Clone the repository:
git clone https://github.com/AKA2114SH/fastapi-blogapplication-mysql.git
cd fastapi-blogapplication-mysql
  1. Create a virtual environment:
python -m venv .vscode
source .vscode/bin/activate  # On Windows: .vscode\Scripts\activate
  1. Install dependencies:
pip install -r requirements.txt
  1. Configure your MySQL database in database.py

  2. Run database migrations:

alembic upgrade head
  1. Start the application:
uvicorn main:app --reload

API Endpoints

Authentication

  • POST /auth/register: Register new user
  • POST /auth/login: Login user

Blog Posts

  • GET /posts: Get all blog posts
  • GET /posts/{id}: Get specific blog post
  • POST /posts: Create new blog post
  • PUT /posts/{id}: Update blog post
  • DELETE /posts/{id}: Delete blog post

Project Structure

fastapi-blogapplication-mysql/
├── alembic/              # Database migrations
├── blog/                 # Blog related modules
├── .vscode/              # Virtual environment
├── main.py              # Application entry point
├── database.py          # Database configuration
├── requirements.txt     # Project dependencies
└── README.md           # Project documentation

Development

The project uses Alembic for database migrations and SQLAlchemy as the ORM. The authentication system is implemented using JWT tokens for secure user sessions.

Database Configuration

Update the database connection string in database.py:

SQLALCHEMY_DATABASE_URL = "mysql+mysqlconnector://user:password@localhost/dbname"

Running Tests

To run the test suite:

pytest

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

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

Acknowledgments

  • FastAPI documentation
  • SQLAlchemy documentation
  • Python community

Contact

Your Name - @AKA2114SH

Project Link: https://github.com/AKA2114SH/fastapi-blogapplication-mysql