Skip to content

Latest commit

 

History

16 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Task API - Week 2 + 3 Assignment (FlyRank Backend Track)

A lightweight, in-memory CRUD To-Do List API built using Python, FastAPI, and Pydantic.


Features

  • In-Memory Storage: Fast execution with zero database setup required.
  • Full CRUD Support: Create, Read, Update, and Delete tasks.
  • Input Validation: Rejects empty or invalid task titles with proper error codes.
  • Interactive Documentation: Auto-generated Swagger UI.

Endpoints Table

Method Path Description Status Codes
GET / API Root self-description 200 OK
GET /health Server health check 200 OK
GET /tasks List all tasks 200 OK
GET /tasks/{id} Get a single task by ID 200 OK, 404 Not Found
POST /tasks Create a new task 201 Created, 400 Bad Request
PUT /tasks/{id} Update an existing task 200 OK, 400 Bad Request, 404 Not Found
DELETE /tasks/{id} Remove a task 204 No Content, 404 Not Found

How to Install & Run

  1. Clone the repository:
    git clone [https://github.com/ahmadrayan-create/task-api.git](https://github.com/ahmadrayan-create/task-api.git)
    cd task-api
    

2. **Create and activate a virtual environment:**
```bash
python -m venv venv
# Windows:
venv\Scripts\activate
# Mac/Linux:
source venv/bin/activate

  1. Install dependencies:
pip install -r requirements.txt
  1. Start the server:
uvicorn main:app --reload --port 8000
  1. Open Swagger UI: Navigate to http://localhost:8000/docs in your browser.

Sample curl Output

PS C:\Users\iamom> irm -Method POST -Uri "http://localhost:8000/tasks" -ContentType "application/json" -Body '{"title":"Test task"}'

id title      done
-- -----      ----
 4 Test task False

Swagger UI Verification

image

Task API - Week 3 Assignment (BE-02: SQLite Database Integration)

An upgraded, persistent CRUD To-Do List API built using Python, FastAPI, SQLModel, and SQLite.


📌 Assignment Context & Evolution

This repository contains the evolution of Assignment 1 (BE-01: In-Memory CRUD API) into a production-ready database-backed application for Assignment 2 (BE-02):

  • Assignment 1: Data lived strictly in a temporary memory list and was wiped out on every server restart.
  • Assignment 2 (Current): Replaced the in-memory array with a lightweight, file-based SQLite database (tasks.db) managed via SQLModel. Data now securely persists across server restarts while keeping the exact same API contract.

🚀 Features

  • Persistent SQLite Storage: Tasks are saved to a local tasks.db file and survive server reboots.
  • Automatic Schema & Seeding: Tables are created automatically on startup, and pre-seeded with 3 initial tasks only if the database is empty.
  • Full CRUD Support: Create (POST), Read (GET), Update (PUT), and Delete (DELETE) tasks.
  • Input Validation: Rejects empty or invalid task titles with proper 400 Bad Request status codes.
  • Interactive Documentation: Auto-generated Swagger UI available out-of-the-box.

📋 Endpoints Table

Method Path Description Status Codes
GET / API Root self-description 200 OK
GET /health Server health check 200 OK
GET /tasks List all tasks from SQLite 200 OK
GET /tasks/{id} Get a single task by ID 200 OK, 404 Not Found
POST /tasks Create a new task in database 201 Created, 400 Bad Request
PUT /tasks/{id} Update an existing task 200 OK, 400 Bad Request, 404 Not Found
DELETE /tasks/{id} Remove a task from database 204 No Content, 404 Not Found

🛠️ How to Install & Run

  1. Clone the repository:
    git clone [https://github.com/ahmadrayan-create/task-api.git](https://github.com/ahmadrayan-create/task-api.git)
    cd task-api
    

2. **Create and activate a virtual environment:**
```bash
python -m venv venv
# Windows PowerShell:
venv\Scripts\Activate.ps1
# Mac/Linux:
source venv/bin/activate

  1. Install dependencies:
pip install -r requirements.txt
  1. Start the server:
uvicorn main:app --reload --port 8000

(Note: The tasks.db file will automatically be created and seeded in your root directory upon startup). 5. Open Swagger UI: Navigate to http://localhost:8000/docs in your browser.


🧪 Sample Execution (irm / PowerShell)

Testing database write and persistence:

# Create a new task
$body = @{ title = "Test database write" } | ConvertTo-Json
irm -Uri "http://localhost:8000/tasks" -Method Post -ContentType "application/json" -Body $body

# Output response:
# id title                done
# -- -----                ----
#  4 Test database write False

📸 Swagger UI Verification

image image image image

About

Lightweight, persistent RESTful CRUD To-Do List API built with Python, FastAPI, SQLModel, and SQLite. Features automatic database schema creation, pre-seeding, Pydantic input validation, and Swagger UI docs. FlyRank Backend Track (BE-01 & BE-02).

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages