Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

FastAPI Todo API

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.

🚀 Features

  • Get all todos
  • Add a new todo
  • Delete a todo
  • Request validation using Pydantic
  • Interactive API documentation using Swagger UI

🛠️ Technologies Used

  • Python
  • FastAPI
  • Uvicorn
  • Pydantic

📁 Project Structure

fastapi_todo/
│
├── main.py
└── README.md

⚙️ Installation

Clone the repository:

git clone https://github.com/piu3574/fastapi_todo.git

Go into the project folder:

cd fastapi_todo

Install the required packages:

pip install fastapi uvicorn

▶️ Run the Application

Start the FastAPI server:

python -m uvicorn main:app --reload

The API will be available at:

http://127.0.0.1:8000

📖 API Documentation

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.

🔗 API Endpoints

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

📝 Example

Add a Todo

POST

/todos

Request body:

{
  "title": "Learn FastAPI",
  "completed": false
}

Response:

{
  "title": "Learn FastAPI",
  "completed": false
}

Get Todos

GET

/todos

Example response:

[
  {
    "title": "Learn FastAPI",
    "completed": false
  }
]

Delete a Todo

DELETE

/todos/0

Response:

{
  "message": "Todo deleted"
}

📚 What I Learned

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

🔮 Future Improvements

  • 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.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages