This project demonstrates a simple, demo backend REST API for a Todo Application built using FastAPI, a modern and fast web framework for building APIs with Python. The API supports basic CRUD operations (Create, Read, Update, Delete) to manage a list of todo items.
This Todo Application provides a RESTful API that allows users to manage their todo items. The API is built using FastAPI, which provides high performance, automatic data validation, and interactive API documentation. It includes endpoints to create, retrieve, update, and delete todo items.
- FastAPI Framework: Built using FastAPI, which provides asynchronous support and high performance.
- CRUD Operations: Create, Read, Update, and Delete operations for managing todo items.
- Automatic API Documentation: Interactive API documentation generated with Swagger UI and ReDoc.
- Pydantic Models: Data validation and serialization using Pydantic models.
- Error Handling: Custom error messages for different HTTP status codes.
- Python 3.7 or higher
-
Clone the Repository:
Clone the repository to your local machine:
git clone https://github.com/your-username/todo-app-fastapi.git
-
Navigate to the Directory:
Go to the project directory:
cd todo-app-fastapi
-
Install Dependencies:
Install FastAPI and Uvicorn using pip:
pip install fastapi uvicorn
-
Run the Application:
Start the FastAPI application using Uvicorn:
uvicorn main:app --reload
The server will start at
http://127.0.0.1:8000/
. -
Access API Documentation:
FastAPI provides interactive API documentation at:
- Swagger UI: http://127.0.0.1:8000/docs
- ReDoc: http://127.0.0.1:8000/redoc
The following endpoints are available:
- Endpoint:
GET /todos
- Description: Retrieve all todo items.
- Response: A list of all todo items.
- Endpoint:
GET /todos/{todo_id}
- Description: Retrieve a specific todo item by its ID.
- Response: The todo item with the specified ID.
- Endpoint:
POST /todos
- Description: Create a new todo item.
- Request Body:
{ "id": 1, "title": "Buy groceries", "description": "Milk, Bread, Cheese, Eggs", "completed": false }
- Response: The newly created todo item.
- Endpoint:
PUT /todos/{todo_id}
- Description: Update an existing todo item by its ID.
- Request Body:
{ "id": 1, "title": "Buy groceries and fruits", "description": "Milk, Bread, Cheese, Eggs, Apples", "completed": false }
- Response: The updated todo item.
- Endpoint:
DELETE /todos/{todo_id}
- Description: Delete a specific todo item by its ID.
- Response: A confirmation message.
-
Create a Todo:
curl -X POST -H "Content-Type: application/json" -d '{"id": 1, "title": "Buy groceries", "description": "Milk, Bread, Cheese, Eggs", "completed": false}' http://127.0.0.1:8000/todos
-
Get All Todos:
curl -X GET http://127.0.0.1:8000/todos
-
Get Todo by ID:
curl -X GET http://127.0.0.1:8000/todos/1
-
Update a Todo:
curl -X PUT -H "Content-Type: application/json" -d '{"id": 1, "title": "Buy groceries and fruits", "description": "Milk, Bread, Cheese, Eggs, Apples", "completed": false}' http://127.0.0.1:8000/todos/1
-
Delete a Todo:
curl -X DELETE http://127.0.0.1:8000/todos/1
Contributions are welcome! If you have ideas for new features, improvements, or bug fixes, please feel free to open an issue or create a pull request.
- Fork the Repository: Click the 'Fork' button at the top right of this page.
- Clone Your Fork: Clone your forked repository to your local machine.
git clone https://github.com/your-username/todo-app-fastapi.git
- Create a Branch: Create a new branch for your feature or bug fix.
git checkout -b feature/your-feature-name
- Make Changes: Make your changes and commit them with a descriptive message.
git commit -m "Add: feature description"
- Push Changes: Push your changes to your forked repository.
git push origin feature/your-feature-name
- Create a Pull Request: Go to the original repository on GitHub and create a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.
Thank you for using the Todo Application Backend with FastAPI! If you have any questions or feedback, feel free to reach out. Happy coding! 📝🚀