Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Task API (FastAPI CRUD)

A lightweight, in-memory CRUD API for managing tasks, built using Python and FastAPI. This project was built step-by-step to demonstrate core backend mechanics, HTTP methods, status codes, and input validation without relying on an external database.

How to Run

Start the local development server with:

uvicorn main:app --reload

The server will be available at http://localhost:8000.

Endpoints

Method Path Action Expected Status Codes
GET / API Information 200
GET /health Health Check 200
GET /tasks List all tasks 200
GET /tasks/{task_id} Get a specific task 200, 404
POST /tasks Create a new task 201, 400
PUT /tasks/{task_id} Update an existing task 200, 400, 404
DELETE /tasks/{task_id} Delete a task 204, 404

Step-by-Step Implementation

Stage 0 & 1: Server Setup and Root Endpoints

  • Initialized the FastAPI application.
  • Created the root GET / endpoint returning basic API metadata.
  • Created the GET /health endpoint for server monitoring.

Stage 2: Read (List and Single Task)

  • Established an in-memory Python list (Task_DB) acting as the database.
  • Implemented GET /tasks to return the complete array of tasks.
  • Implemented GET /tasks/{task_id} to return a specific task, utilizing a 404 Not Found exception if the ID does not exist.

Stage 3: Create (POST a new task)

  • Implemented POST /tasks accepting a JSON body mapped to a Pydantic TaskCreate model.
  • Added validation to ensure the title cannot be empty, triggering a custom 400 Bad Request global exception handler.
  • Automatically generates an incremented ID and defaults the done status to false.

Example POST Request via curl:

curl -i -X POST http://localhost:8000/tasks -H "Content-Type: application/json" -d "{\"title\":\"Test task from terminal\"}"

HTTP/1.1 201 Created
date: Tue, 21 Jul 2026 11:32:22 GMT
server: uvicorn
content-length: 71
content-type: application/json

{"status":"New Task Added Successfully","Task":{"id":2,"title":"Test task from terminal","done":false}}

Stage 4: Update & Delete

  • Implemented PUT /tasks/{task_id} using a TaskUpdate model to allow partial updates of title or done fields. Includes 400 validation for empty titles and 404 for missing IDs.
  • Implemented DELETE /tasks/{task_id} removing the task dictionary from the list using .remove() and returning a 204 No Content status.
  • The Mortality Experiment: Confirmed that because data is stored in memory, restarting the server (via Uvicorn's reload functionality) wipes out all dynamically created tasks and resets to the original hardcoded state.

Stage 5: Swagger UI

  • Utilized FastAPI's built-in interactive documentation available at /docs.
  • Tested the full CRUD cycle visually without manual curl formatting.

Swagger Documentation Screenshots:

![Swagger UI Endpoints](Swagger UI 1.png)

![Swagger UI Schemas](Swagger UI 2.png)

Stage 6: Publish to GitHub

  • Initialized the local Git repository.
  • Documented the API requirements, behavior, and testing steps in this README.
  • Pushed all iterative commits to the remote repository.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages