Git Product home page Git Product logo

http-endpoint-api-delivery-calc's Introduction

Delivery Fee Calculator FastAPI App

Brief Description

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.

Usage

The application exposes an endpoint (/delivery_fee) that accepts POST requests with JSON payload containing delivery information. It returns the calculated delivery fee.

Endpoint

  • POST /delivery_fee: Accepts a JSON object with cart_value, delivery_distance, number_of_items, and time. Returns the calculated delivery fee.

Response status codes

  • 200: Successful Response
  • 400: Bad Request
  • 422: Validation Error

Example Query

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
}

Instructions

Prerequisites

  • Python 3.8+
  • Other dependencies in requirements.txt

Setup and Running Locally

  1. Clone the repository.
  2. Install dependencies: pip install -r requirements.txt.
  3. Run the application: uvicorn --workers 1 --host 0.0.0.0 --port 5000 api_app:app.

Docker Usage

Alternatively, you can build and run this app using Docker:

  1. Build the Docker image: docker build -t delivery-fee-calculator .
  2. Run the Docker container: docker run -p 5000:5000 delivery-fee-calculator

Tests

The tests directory contains unit tests for the delivery fee calculation logic, and the endpoint response.

Running Tests

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

Documentation built by sphinx: Docs

http-endpoint-api-delivery-calc's People

Contributors

mamdasn avatar

Stargazers

Rouhollah Ghobadinezhad avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.