A RESTful Flask api for managing tasks with sorting, searching, and filtering capabilities. First major API app created by author.
# Install dependencies
pip install -r requirements.txtTo instantiate the database I found running the following commands in an interactive python shell to be the easiest approach
# Import app and db from app.py
from app import db, app
# Use app context manager to create database
with app.app_context():
db.create_all()The main app.py file has code to start the Flask app API embedded within so it can be ran either way below
# Using flask command(debug mode OFF by default)
flask run
# Using python command(debug mode ON by default)
python app.pyFirst API Call:
curl -X GET "http://localhost:5000/api/tasks"http://localhost:5000/api/tasks
No authentication requirements needed. This is just a small practice project.
GET /api/tasks
search(string, optional): Filter tasks by name containing search termsort(string, optional): Sorts task by fieldname,due_date,priority,statuspriority(string, optional): Returns tasks with specified priorityLow,Medium,Highstatus(string, optional): Returns tasks with specified statusPending,In Progress,Completeddue_date(string, optional): Returns tasks with specified due date. Formatted yyyy-mm-dd
curl GET "http://localhost:5000/api/tasks?priority=High&sort=due_date"[
{
"due_date": "2025-07-28T00:00:00",
"id": 2,
"name": "Complete Flask README.md",
"priority": "High",
"status": "In Progress"
},
{
"due_date": "2025-07-30T00:00:00",
"id": 1,
"name": "Finish Flask app",
"priority": "High",
"status": "In Progress"
}
]POST /api/tasks
{
"name": "Task name (required)",
"priority": "Low|Medium|High (optional, defaults to Medium)",
"status": "Pending|In Progress|Completed (optional, defaults to Pending)",
"due_date": "YYYY-MM-DD (Optional)"
}curl -X POST "http://localhost:5000/api/tasks" \
-H "Content-Type: application/json" \
-d '{
"name": "Implement testing suite",
"due_date": "2025-07-29"
}'{
"due_date": "2025-07-29T00:00:00",
"id": 3,
"name": "Implement testing suite",
"priority": "Medium",
"status": "Pending"
}PUT /api/tasks/{task_id}
{task_id}(integer, required): ID of the task to update
Same as the request body for POST requests (all fields optional)
curl -X PUT "http://localhost:5000/api/tasks/3" \
-H "Content-Type: application/json" \
-d '{"status": "In Progress",
"due_date": "2025-07-31
}'{
"due_date": "2025-07-31T00:00:00",
"id": 3,
"name": "Implement testing suite",
"priority": "Medium",
"status": "In Progress"
}DELETE /api/task/{task_id}
- {task_id} (integer, required): ID of task to be deleted
curl -X DELETE "http://localhost:5000/api/tasks/2"{
"message": "task successfully deleted"
}All errors return JSON in the following format:
{
"details": "additional details (optional)",
"error": "error description",
"status": "error status code"
}{
"details": {
"due_date": [
"Not a valid datetime."
],
"name": [
"Shorter than minimum length 2."
],
"status": [
"Must be one of: Completed, In Progress, Pending."
]
},
"error": "Invalid data",
"status": 400
}