This FastAPI application provides an API for calculating delivery fees based on various factors such as cart value, delivery distance, number of items, and time.
The application exposes an endpoint (/delivery_fee
) that accepts POST requests with JSON payload containing delivery information. It returns the calculated delivery fee.
- POST
/delivery_fee
: Accepts a JSON object withcart_value
,delivery_distance
,number_of_items
, andtime
. Returns the calculated delivery fee.
200
: Successful Response400
: Bad Request422
: Validation Error
Example sent query to /delivery_fee
:
{
"cart_value": 890,
"delivery_distance": 1,
"number_of_items": 1,
"time": "2024-01-15T13:00:00Z",
}
/delivery_fee
's response:
{
"delivery_fee": 310
}
- Python 3.8+
- Other dependencies in
requirements.txt
- Clone the repository.
- Install dependencies:
pip install -r requirements.txt
. - Run the application:
uvicorn --workers 1 --host 0.0.0.0 --port 5000 api_app:app
.
Alternatively, you can build and run this app using Docker:
- Build the Docker image:
docker build -t delivery-fee-calculator .
- Run the Docker container:
docker run -p 5000:5000 delivery-fee-calculator
The tests
directory contains unit tests for the delivery fee calculation logic, and the endpoint response.
Run the tests using the following command:
python -m unittest discover -s tests -v
The implemented tests can also be executed using the pytest
testing tool.
This will execute various test cases defined in test_delivery_fee.py
and test_delivery_fee_http_api.py
, evaluating the logic of the delivery fee calculations and the http endpoint responses under different scenarios.
Documentation built by sphinx
: Docs