An intermediate-level REST API built with Flask and SQLite, featuring a complete CRUD system with database relationships, foreign keys, and transaction handling.
- Full CRUD Operations: Create, Read, Update, and Delete tasks
- SQLite Database: Persistent data storage with proper schema design
- Foreign Key Relationships: Categories linked to tasks with referential integrity
- Transaction Handling: Atomic operations with COMMIT/ROLLBACK
- Auto-Category Creation: Categories are automatically created when adding tasks
- Data Validation: CHECK constraints for status and priority fields
- Professional Error Handling: Proper HTTP status codes and error messages
- Python 3
- Flask (Web Framework)
- SQLite3 (Database)
- RESTful API design principles
CREATE TABLE categories (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL UNIQUE,
created_at TEXT
)CREATE TABLE tasks (
id INTEGER PRIMARY KEY AUTOINCREMENT,
title TEXT NOT NULL,
description TEXT,
priority TEXT NOT NULL DEFAULT 'Medium',
due_date TEXT,
status TEXT NOT NULL DEFAULT 'Pending',
created_at TEXT NOT NULL,
category_id INTEGER NOT NULL,
FOREIGN KEY (category_id) REFERENCES categories(id),
CHECK(status IN('Pending', 'In Progress', 'Completed')),
CHECK(priority IN('Low', 'Medium', 'High'))
)GET /api/tasks
Response: Array of all tasks with category information
GET /api/tasks/<id>
Response: Single task object or 404 error
POST /api/tasks
Content-Type: application/json
{
"title": "Task name",
"description": "Task description",
"priority": "High",
"due_date": "2025-12-20",
"category": "Work"
}
Response: 201 Created with success message
PUT /api/tasks/<id>
Content-Type: application/json
{
"status": "Completed",
"priority": "Low"
}
Response: 200 OK with success message or 404 if not found
DELETE /api/tasks/<id>
Response: 200 OK with success message or 404 if not found
- Clone the repository:
git clone https://github.com/jandaghi14/intermediate-flask-sqlite-task-api.git
cd intermediate-flask-sqlite-task-api- Install Flask:
pip install flask- Run the application:
python app.py- Server runs on:
http://127.0.0.1:5000
Create a task:
curl -X POST http://127.0.0.1:5000/api/tasks -H "Content-Type: application/json" -d "{\"title\": \"Learn Flask\", \"description\": \"Build REST APIs\", \"priority\": \"High\", \"due_date\": \"2025-12-20\", \"category\": \"Education\"}"Get all tasks:
curl http://127.0.0.1:5000/api/tasksGet single task:
curl http://127.0.0.1:5000/api/tasks/1Update task status:
curl -X PUT http://127.0.0.1:5000/api/tasks/1 -H "Content-Type: application/json" -d "{\"status\": \"Completed\"}"Delete task:
curl -X DELETE http://127.0.0.1:5000/api/tasks/2- PRAGMA foreign_keys = ON ensures referential integrity
- Tasks cannot exist without a valid category
- Categories are protected from deletion if tasks reference them
- All database operations use proper commit/rollback patterns
- Connection pooling is handled correctly
- No orphaned connections or memory leaks
- UPDATE operations only modify specified fields
- NULL values are handled correctly
- SQL injection is prevented with parameterized queries
intermediate-flask-sqlite-task-api/
│
├── app.py # Flask application and API routes
├── database.py # Database operations and schema
├── .gitignore # Git ignore rules
└── README.md # Project documentation
- Building RESTful APIs with Flask
- SQLite database design with foreign keys
- Transaction management and data integrity
- HTTP methods and status codes
- API testing with curl
- Professional error handling
- Modular code architecture
- Git workflow and GitHub collaboration
- Add user authentication (JWT tokens)
- Implement pagination for large datasets
- Add data validation middleware
- Create API documentation (Swagger/OpenAPI)
- Deploy to production (Heroku/PythonAnywhere)
- Add unit tests (pytest)
- Implement rate limiting
- Add category management endpoints
This project is open source and available for educational purposes.
Built as part of a Python learning journey - Day 48 of 225 days to job-ready.