A simple Flask application with complete CRUD (Create, Read, Update, Delete) operations for task management.
- ✅ Create new tasks
- ✅ Read all tasks or specific task by ID
- ✅ Update existing tasks
- ✅ Delete tasks
- ✅ Filter tasks by completion status
- ✅ Search tasks by title or description
- ✅ Health check endpoint
- ✅ Proper error handling and validation
- ✅ JSON responses
- Install dependencies:
pip install -r requirements.txt
- Run the Flask application:
python app.py
The API will be available at http://localhost:5000
- GET
/api/health
- Returns API status and task count
- GET
/api/tasks
- Query parameters:
completed=true/false
- Filter by completion statussearch=term
- Search in title and description
- GET
/api/tasks/<task_id>
- Returns a specific task by ID
- POST
/api/tasks
- Required fields:
title
,description
- Optional fields:
completed
(defaults to false)
- PUT
/api/tasks/<task_id>
- Fields to update:
title
,description
,completed
- DELETE
/api/tasks/<task_id>
- Removes the task from the system
curl -X POST http://localhost:5000/api/tasks \
-H "Content-Type: application/json" \
-d '{
"title": "Learn Flask",
"description": "Build a CRUD API with Flask",
"completed": false
}'
curl http://localhost:5000/api/tasks
curl "http://localhost:5000/api/tasks?completed=true"
curl "http://localhost:5000/api/tasks?search=flask"
curl -X PUT http://localhost:5000/api/tasks/<task_id> \
-H "Content-Type: application/json" \
-d '{
"title": "Learn Flask - Updated",
"completed": true
}'
curl -X DELETE http://localhost:5000/api/tasks/<task_id>
Run the included test script to verify all endpoints:
python test_api.py
Make sure the Flask app is running before executing the test script.
Visit http://localhost:5000/
to see the interactive API documentation with all available endpoints and example payloads.
Each task has the following structure:
{
"id": "unique-uuid",
"title": "Task title",
"description": "Task description",
"completed": false,
"created_at": "2024-01-01T12:00:00.000000",
"updated_at": "2024-01-01T12:00:00.000000"
}
- This implementation uses in-memory storage for simplicity
- In production, replace with a proper database (PostgreSQL, MySQL, etc.)
- All timestamps are in ISO format
- Task IDs are generated using UUID4 for uniqueness