A simple FastAPI project with MySQL, following RESTful API principles to manage resources using CRUD operations (Create, Read, Update, Delete).
- FastAPI for high-performance APIs
- MySQL database integration
- SQLAlchemy for ORM
- Pydantic for data validation
- RESTful API structure
- FastAPI (Backend Framework)
- MySQL (Database)
- SQLAlchemy (ORM for database interaction)
- Pydantic (Data validation)
- Uvicorn (ASGI server for running FastAPI)
git clone https://github.com/Bhumigor/Fastapi-Restful-App.git
cd Fastapi-Restful-App
python -m venv venv
source venv/bin/activate # On macOS/Linux
venv\Scripts\activate # On Windows
pip install -r requirements.txt
Create a .env
file and add your database configuration:
DATABASE_URL=mysql+pymysql://username:password@localhost/db_name
uvicorn main:app --reload
Method | Endpoint | Description |
---|---|---|
GET | /items/ |
Get all items |
GET | /items/{item_id} |
Get item by ID |
POST | /items/ |
Create a new item |
PUT | /items/{item_id} |
Update an existing item |
DELETE | /items/{item_id} |
Delete an item |
📌 Visit API Docs: Open http://127.0.0.1:8000/docs
in your browser for interactive API documentation.
Fastapi-Restful-App/
│── main.py # FastAPI application entry point
│── models.py # Database models using SQLAlchemy
│── routes.py # API endpoints
│── schemas.py # Pydantic models for validation
│── database.py # Database connection setup
│── config.py # Configuration settings
│── requirements.txt # Project dependencies
│── .env # Environment variables (ignored in Git)
Feel free to fork, create issues, and submit PRs! 🚀
💡 Happy Coding! 😊