A simple Todo REST API built using FastAPI and Python. This project demonstrates the basic concepts of creating API endpoints, handling request data, and performing CRUD-style operations.
- Get all todos
- Add a new todo
- Delete a todo
- Request validation using Pydantic
- Interactive API documentation using Swagger UI
- Python
- FastAPI
- Uvicorn
- Pydantic
fastapi_todo/
│
├── main.py
└── README.md
Clone the repository:
git clone https://github.com/piu3574/fastapi_todo.gitGo into the project folder:
cd fastapi_todoInstall the required packages:
pip install fastapi uvicornStart the FastAPI server:
python -m uvicorn main:app --reloadThe API will be available at:
http://127.0.0.1:8000
FastAPI automatically provides interactive API documentation.
Open:
http://127.0.0.1:8000/docs
You can test all the endpoints directly from the Swagger UI.
| Method | Endpoint | Description |
|---|---|---|
| GET | / |
Check if the API is running |
| GET | /todos |
Get all todos |
| POST | /todos |
Add a new todo |
| DELETE | /todos/{todo_id} |
Delete a todo |
POST
/todos
Request body:
{
"title": "Learn FastAPI",
"completed": false
}Response:
{
"title": "Learn FastAPI",
"completed": false
}GET
/todos
Example response:
[
{
"title": "Learn FastAPI",
"completed": false
}
]DELETE
/todos/0
Response:
{
"message": "Todo deleted"
}This project helped me understand:
- FastAPI application setup
- API routes and endpoints
- GET, POST, and DELETE HTTP methods
- Path parameters
- Request bodies
- Pydantic models and validation
- Running FastAPI with Uvicorn
- Testing APIs using Swagger UI
- Basic Git and GitHub workflow
- Add PUT endpoint to update todos
- Add a database such as SQLite or PostgreSQL
- Add proper error handling
- Add authentication
- Deploy the API online
Built as a beginner project to learn FastAPI and REST API development.