iplitharas / srv-comm

Example of two services communicate over HTTP

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Table of Contents

Test pre-commit Code Style PyPI - Implementation

About the project

The project is structured with two different modules, the server and the client. The server is built with FastAPI and exposes one single endpoint greet/ that accepts a POST request with a JSON payload. The logic of this service is under src/services/srv_b to be able to abstract the logic of the service from the server itself.

Same for the client, the logic of the this service is under src/services/srv_a alongside with an HTTPClient to abstract the logic of the client from the main file.

The entrypoint for the client service is at

  • src/client.py
  • and the entrypoint for the server service is at src/server.py

Installation 🛠️

To automate the whole process of installing the project and its dependencies, the project list the python dependencies in the pyproject.toml file and a MakeFile to automate the process. The requirements are poetry, make and pyenv to manage the python version. Otherwise, you can install the dependencies manually with min requirement python = ">=3.11,<3.13"

python -m venv .env 
source .env/bin/activate
pip install -r requirements.txt

or

make setup-local-dev

Usage

Start the server by running the following command in the terminal

uvicorn src.main:app --reload

In a separate terminal, run the following command to test the server, by default the client will send 10 requests to the server, you can change the number of requests by changing the argument.

python -m src.client 30

sample-out.png

Running test cases

To run the test cases, run the following command in the terminal

make test-local

Missing Features

  1. Refactor all constants to a single config using pydantic settings to manage the configuration of the server and the client using environment variables.
  2. Add a Dockerfile to containerize the server and the client.

About

Example of two services communicate over HTTP


Languages

Language:Python 90.1%Language:Makefile 9.9%