0% found this document useful (0 votes)
11 views3 pages

FastAPI Task Manager API Guide

The document outlines the creation of a RESTful API for a Task Manager application using FastAPI and PostgreSQL. It specifies mandatory requirements including CRUD functionality, input validation, error handling, and a Docker Compose setup. Additionally, it provides a data model for tasks and example endpoints for API interaction.

Uploaded by

Pankaj Dadwal
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views3 pages

FastAPI Task Manager API Guide

The document outlines the creation of a RESTful API for a Task Manager application using FastAPI and PostgreSQL. It specifies mandatory requirements including CRUD functionality, input validation, error handling, and a Docker Compose setup. Additionally, it provides a data model for tasks and example endpoints for API interaction.

Uploaded by

Pankaj Dadwal
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Python API Assessment

Objective:
Create a RESTful API for managing a basic "Task Manager" application. The API
will allow users to perform CRUD (Create, Read, Update, Delete) operations on
tasks using FastAPI and PostgreSQL.
Note: Use of ChatGPT or any AI assistance in building the application is
strictly prohibited.

Requirements
Tech Stack (Mandatory):
 FastAPI for API development.
 PostgreSQL as the database.
 Docker Compose for container orchestration.
 SQLAlchemy or equivalent ORM for database interaction.

Tasks Data Model:


Each task must include the following attributes:
 id (integer): Unique identifier for the task (Auto-incremented).
 title (string): Title of the task.
 description (string): Description of the task.
 completed (boolean): Status of the task (default is false).

Functional Requirements:
 Implement full CRUD functionality for tasks.
 Input validation (e.g., title and description must not be empty).
 Error handling (e.g., task not found, invalid input, etc.).

Additional Requirements:
 Use PostgreSQL as the database backend (no in-memory or file-based
DBs).
 Provide a Docker Compose setup to run both the FastAPI app and the
PostgreSQL database.
 All configuration should be set via environment variables (e.g., DB URL).
 Database schema initialization (e.g., migrations or SQL scripts) must be
included.
 Endpoints should follow RESTful principles.

Expected Deliverables:
 A complete FastAPI project directory structure (not a single script).
 A [Link] file to spin up the API and database.
 Instructions in a [Link] on how to:
o Build and run the application using Docker Compose.

o Interact with the API using tools like curl or Postman.

Example Endpoints:
POST /tasks
Request:
{
"title": "Complete Python Assessment",
"description": "Implement a REST API for task management."
}
Response:
{
"id": 1,
"title": "Complete Python Assessment",
"description": "Implement a REST API for task management.",
"completed": false
}

GET /tasks
Response:
[
{
"id": 1,
"title": "Complete Python Assessment",
"description": "Implement a REST API for task management.",
"completed": false
}
]

GET /tasks/99 (Non-existent ID)


Response:
{
"error": "Task not found"
}

Common questions

Powered by AI

CRUD functionality—comprising Create, Read, Update, and Delete operations—is fundamental to the task manager API as it covers the essential interactions needed to fully manage tasks. This functionality enables users to create new tasks, retrieve task data for viewing or processing, update existing tasks to modify details or status, and delete tasks no longer needed. Such comprehensive capabilities ensure that the API meets diverse user needs, supporting both individual and batch operations effectively while maintaining data integrity and consistency .

SQLAlchemy, or an equivalent ORM, plays a crucial role by serving as an intermediary between the database and the application code. It allows developers to interact with the PostgreSQL database using Python objects rather than raw SQL queries. This abstraction simplifies complex database operations, maintains ANSI compliance, improves code readability, and integrates seamlessly with FastAPI to manage CRUD operations efficiently within the application architecture .

Including a boolean 'completed' field in each task attribute is pivotal for actively managing task status within the API. It provides a simple, efficient method to track the progress of tasks, allowing for instantaneous state-based filtering of tasks (e.g., completed vs. incomplete). This facilitates task prioritization, reporting, and management processes, enhancing the end-user's ability to organize and assess task workloads effectively within a task management system .

Including database schema initialization through migrations or SQL scripts ensures that the database structure is consistently and predictably established at the desired version, minimizing manual setup errors. It facilitates version control of the database schema, providing automatic updates and rollbacks to accommodate app changes over time. This practice enhances continuity and reliability in database management, supporting agile development and deployment processes .

Using environment variables for configuration is significant as it enhances security by preventing sensitive information (e.g., database URLs, credentials) from being hard-coded in source files. It allows for increased portability and flexibility, enabling the application to be easily run in different environments without code changes. Environment variables decouple configuration from deployment, facilitating different deployments and development environments without altering the codebase, ensuring consistent behavior .

Docker Compose allows for the definition and management of multi-container Docker applications, like the task manager API. It simplifies deployment by providing a configuration file (docker-compose.yml) to launch both the FastAPI application and the PostgreSQL database in coordinated, isolated containers. This setup ensures service availability, simplifies environment configuration using environment variables, and provides convenient scaling and networking between components .

RESTful principles guide endpoint design by ensuring that the API uses stateless, client-server communication, and implements resource-based URIs with standard HTTP methods (GET, POST, PUT, DELETE). Adherence to these principles ensures that the API remains scalable, efficient, and easy to consume, providing predictable behavior across interactions (e.g., consistent resource identification via URIs). This allows consumers to seamlessly integrate and utilize the API with minimal dependency, enhancing interoperability and standardization .

Data integrity in the task manager API is maintained by implementing input validation and error handling mechanisms. The document specifies checks such that the 'title' and 'description' fields must not be empty to ensure valid inputs. Error handling routines address scenarios such as non-existent task references and invalid inputs, which maintain application robustness by providing consistent and coherent API responses while avoiding incorrect data operations .

The key components include FastAPI for API development, PostgreSQL for the database, Docker Compose for container orchestration, and SQLAlchemy or an equivalent ORM for database interaction. The application must support CRUD operations, have input validation and error handling, use Docker Compose for setup, and all configurations should use environment variables .

Providing a README.md with detailed instructions is crucial as it serves as a comprehensive guide for users to efficiently build and run the application using Docker Compose. It ensures that all necessary information, including prerequisites, commands, and potential troubleshooting steps, is centralized in one location. This fosters ease of setup, facilitates onboarding, and ensures that the application can be consistently deployed and utilized correctly, aligning with best practices in documentation .

You might also like