🚀 Study project - Complete task management API with full CRUD operations
A fully-featured task management API built with Flask. This is a comprehensive learning project from Rocketseat's Backend with Python track that demonstrates core backend development concepts including REST API design, request validation, error handling, and comprehensive test coverage.
✅ Complete Core Implementation - All CRUD operations fully implemented and tested. Comprehensive test suite covers all endpoints.
- ✅ Create Tasks (POST /tasks) - Add new tasks with title and description
- ✅ List All Tasks (GET /tasks) - Retrieve all tasks with total count
- ✅ Get Task by ID (GET /tasks/) - Fetch a specific task
- ✅ Update Tasks (PATCH /tasks/) - Modify task details and completion status
- ✅ Delete Tasks (DELETE /tasks/) - Remove tasks permanently
- ✅ Automatic API Documentation - Swagger/OpenAPI docs auto-generated at /apidocs/
- ✅ Comprehensive Test Suite - Full integration testing with pytest
- Python 3.7+ - Modern Python runtime
- Flask 2.3.0 - Lightweight web framework for building REST APIs
- Werkzeug 2.3.0 - WSGI utilities and development server
- Flasgger - Swagger/OpenAPI documentation for Flask
- Requests 2.31.0 - HTTP client library for testing
- Pytest 7.4.3 - Modern Python testing framework for integration tests
flask-todo/
├── app/
│ ├── models/
│ │ └── task.py # Task model class with domain logic
│ ├── schemas/
│ │ └── task.py # Task TypedDict schema for type hints
│ ├── routes/
│ │ └── task_route.py # Route handlers with business logic
│ └── app.py # Main Flask application & route registration
├── tests.py # Comprehensive integration test suite
├── requirements.txt # Project dependencies
└── README.md # This documentation file
app/ - Main application package
models/task.py- Task model class managing task properties and conversion methodsschemas/task.py- TypedDict schema defining task data structure and typesroutes/task_route.py- Business logic for all CRUD operationsapp.py- Flask app initialization, route registration, and Swagger configuration
Root Files
tests.py- Integration tests covering all 5 endpoints with full CRUD operationsrequirements.txt- pip dependencies (Flask, Pytest, Requests, etc.)README.md- Project documentation
- Python 3.7+ - Ensure you have Python installed on your system
- pip - Python package manager (comes with Python 3.7+)
- Virtual environment - Recommended for dependency isolation
- Clone the repository:
git clone <your-repository>
cd flask-todo- Create a virtual environment:
python -m venv venv
source venv/bin/activate # macOS/Linux
# or
venv\Scripts\activate # Windows- Install dependencies:
pip install -r requirements.txtThis installs Flask, Flasgger, Requests, and Pytest as specified in requirements.txt.
Start the development server:
python app/app.pyAccess the application:
- API Server: http://localhost:5001
- Interactive API Docs (Swagger): http://localhost:5001/apidocs/
- ReDoc Docs: http://localhost:5001/redoc/
Execute the full test suite:
pytest tests.pyOr with verbose output:
pytest tests.py -vNote: The test server must be running (in another terminal) for tests to pass, as they perform integration tests against the live API.
All endpoints return JSON responses and support standard HTTP status codes. Base URL: http://localhost:5001
POST /tasks
Creates a new task with the provided title and description.
Request Body:
{
"title": "Study Flask",
"description": "Learn how to build APIs with Flask"
}Response (201 Created)
{
"message": "New task created successfully"
}Requirements:
title(string, required) - Task titledescription(string, required) - Task description
GET /tasks
Retrieves all tasks with pagination information.
Response (200 OK)
{
"tasks": [
{
"id": 1,
"title": "Study Flask",
"description": "Learn how to build APIs with Flask",
"is_completed": false
}
],
"total_tasks": 1
}Returns:
tasks(array) - List of all taskstotal_tasks(number) - Count of total tasks
GET /tasks/<id>
Retrieves a specific task by its ID.
Path Parameters:
id(integer, required) - Task ID
Response (200 OK)
{
"task": {
"id": 1,
"title": "Study Flask",
"description": "Learn how to build APIs with Flask",
"is_completed": false
}
}Response (404 Not Found)
{
"message": "Task not found"
}PATCH /tasks/<id>
Updates a specific task's properties. All fields are optional.
Path Parameters:
id(integer, required) - Task ID
Request Body (all optional):
{
"title": "Study Flask Advanced",
"description": "Learn advanced Flask concepts and best practices",
"is_completed": true
}Response (204 No Content) - Successful update, no response body
Response (404 Not Found)
{
"message": "Task not found"
}DELETE /tasks/<id>
Permanently removes a task from the database.
Path Parameters:
id(integer, required) - Task ID
Response (204 No Content) - Task deleted successfully, no response body
Response (404 Not Found)
{
"message": "Not found"
}| Status | Meaning | Used By |
|---|---|---|
| 200 | OK - Request successful | GET requests |
| 201 | Created - Resource created successfully | POST /tasks |
| 204 | No Content - Request successful, no content to return | PATCH, DELETE |
| 404 | Not Found - Resource doesn't exist | GET, PATCH, DELETE with invalid ID |
{
id: number // Unique task identifier (auto-generated)
title: string // Task title (required)
description: string // Task description (required)
is_completed: boolean // Completion status (default: false)
}Separation of Concerns:
- Models (
app/models/) - Domain objects and data structures - Schemas (
app/schemas/) - Type definitions using TypedDict for type safety - Routes (
app/routes/) - Business logic and request handling - Application (
app/app.py) - Flask app initialization and route registration
Data Flow:
HTTP Request → Flask Route Handler → Business Logic (routes) → Data Model → Response
The project uses Python's TypedDict for type hints, providing static type checking without runtime overhead.
- Integration Tests - Tests run against a live server instance
- Test Coverage - All 5 endpoints covered with success and error cases
- Test Utilities - Helper functions reduce code duplication
Execute the full test suite:
pytest tests.py -vThe test suite includes integration tests for all endpoints:
| Endpoint | Test | Status |
|---|---|---|
| POST /tasks | test_create_task() |
✅ Implemented |
| GET /tasks | test_get_tasks() |
✅ Implemented |
| GET /tasks/ | test_get_task() |
✅ Implemented |
| PATCH /tasks/ | test_update_task() |
✅ Implemented |
| DELETE /tasks/ | test_delete_task() |
✅ Implemented |
- Terminal 1 - Start the server:
python app/app.py- Terminal 2 - Run tests:
pytest tests.py -v- Files: 7 core files (models, schemas, routes, app, tests)
- Routes: 5 endpoints (full CRUD operations)
- Tests: 5 integration test cases
- Lines of Code: ~200 (excluding tests)
- Dependencies: 4 core libraries
This project demonstrates:
- RESTful API design principles
- Flask framework fundamentals
- Request/response handling
- HTTP status codes and semantics
- JSON data serialization
- Type hints in Python
- Integration testing with Pytest
- Swagger/OpenAPI documentation
- Error handling and validation
- Code organization and separation of concerns
Developed during Rocketseat studies - Backend with Python track
This project is open source and available for educational purposes.
Contributions are welcome! Feel free to submit issues or pull requests to improve this learning project.