Request Stream API is a FastAPI-based application designed to handle user requests efficiently. It utilizes asynchronous programming to ensure high performance and scalability. The API supports various operations such as creating, updating, retrieving, and deleting applications.
- Asynchronous request handling using FastAPI
- PostgreSQL as the database with SQLAlchemy ORM
- Kafka for message queuing
- Redis for caching
- Alembic for database migrations
- Comprehensive error handling
- Detailed logging with Structlog
To run the application, it is sufficient to use Docker.
- Python 3.12 or higher
- FastAPI
- PostgreSQL
- Kafka
- Redis
-
Clone the repository:
git clone https://github.com/ACK1D/request-stream-api.git cd request-stream-api -
Using Docker: To run the application using Docker, you can use the provided
compose.ymlfile. Make sure to have Docker and Docker Compose installed.-
Copy the example environment file:
cp .env.example .env
Build and start the containers:
docker compose -f docker/compose.yml up --build -d
Access the API documentation at
http://localhost:8000/docs. -
-
Using Poetry: If you prefer to run the application locally without Docker, you can use Poetry for dependency management.
-
Install Poetry if you haven't already:
curl -sSL https://install.python-poetry.org | python3 - -
Create a virtual environment and install dependencies:
poetry install
-
Set up the environment variables. Create a
.envfile in the root directory with the following content:POSTGRES_SERVER=localhost POSTGRES_USER=your_user POSTGRES_PASSWORD=your_password POSTGRES_DB=applications KAFKA_BOOTSTRAP_SERVERS=localhost:9092 REDIS_URL=redis://localhost:6379
-
Run the database migrations:
poetry run alembic upgrade head
-
Start the application using Granian:
poetry run granian --interface asgi --host 0.0.0.0 --port 8000 src.main:app
-
-
Create Application
POST /api/v1/applications/- Request body:
{"user_name": "string", "description": "string"} - Response:
201 Createdwith application details.
-
Get Application by ID
GET /api/v1/applications/{application_id}- Response:
200 OKwith application details or404 Not Found.
-
Get Applications List
GET /api/v1/applications/- Query parameters:
page,size,user_name - Response:
200 OKwith a list of applications.
-
Update Application
PUT /api/v1/applications/{application_id}- Request body:
{"user_name": "string", "description": "string"} - Response:
200 OKwith updated application details or404 Not Found.
-
Partially Update Application
PATCH /api/v1/applications/{application_id}- Request body:
{"description": "string"} - Response:
200 OKwith updated application details or404 Not Found.
-
Delete Application
DELETE /api/v1/applications/{application_id}- Response:
204 No Contentor404 Not Found.
-
Check Application Exists
HEAD /api/v1/applications/{application_id}- Response:
200 OKif the application exists or404 Not Found.
To run the tests, use:
pytest