Skip to content

The Delivery Cost Calculator API is a backend service that determines the most cost-effective delivery option by selecting the optimal warehouse based on product weight and customer location. It helps logistics and e-commerce platforms reduce delivery costs through real-time, distance-based calculations using simple API requests.

License

Notifications You must be signed in to change notification settings

akshayhat/Delivery-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Delivery Cost Calculator API

A scalable REST API to calculate minimum delivery costs based on product weight, order location, and warehouse distance. Optimized for logistics and e-commerce platforms.

Features

  • Calculates minimum delivery cost for orders
  • Supports weighted delivery fees based on distance and weight
  • Multi-warehouse support with auto-selection
  • JSON-based input and output for easy integration
  • Unit-tested API endpoints

Tech Stack

  • Language: Python / Node.js
  • Framework: FastAPI / Express.js
  • Database: PostgreSQL / In-memory (if no DB used)
  • Deployment: Render / Railway / AWS / GCP (your choice)

Installation

To set up and run the project locally, follow these steps:

  1. Clone the repository
git clone https://github.com/akshayhat/delivery-api.git
cd delivery-api
  1. Install Dependencies
npm install
  1. Configure Enviournment
  • Create a .env file in the root directory:
PORT=5000
WAREHOUSE_DATA_SOURCE=./warehouses.json
  1. Install the Server
npm run dev   # For development using nodemon
# OR
npm start     # For production
  1. Test The API
  • Use Tools like Postman or curl to test the endpoints.

Usage

  • Once your server is running, you can make API calls using any REST client like Postman, Thunder Client, or curl.

Start The Server

# Node.js
npm run dev       # or npm start

# FastAPI (Python)
uvicorn main:app --reload

Example API Call (using Curl)

curl -X POST http://localhost:5000/api/calculate-cost \
  -H "Content-Type: application/json" \
  -d '{
        "orderLocation": "Delhi",
        "weight": 10.5,
        "productId": "P001"
      }'
  • You should get a JSON response with the best warehouse and cost.

📤 API Endpoints

## 📤 API Endpoints

### 🔹 `POST /api/calculate-cost`

📌 **Description**: Calculates the minimum delivery cost based on the order location, product weight, and available warehouses.

#### ✅ Request Body

```json
{
  "orderLocation": "Delhi",
  "weight": 10.5,
  "productId": "P001"
}

Response

{
  "minimumCost": 135.75,
  "selectedWarehouse": "Warehouse-B",
  "distance": 52.4,
  "currency": "INR"
}

GET /api/warehouses

  • Lists all available warehouses with coordinates.

Response

[
  {
    "name": "Warehouse-A",
    "location": "Delhi",
    "latitude": 28.6139,
    "longitude": 77.2090
  },
  {
    "name": "Warehouse-B",
    "location": "Noida",
    "latitude": 28.5355,
    "longitude": 77.3910
  }
]

Future Improvements

  • Add JWT authentication
  • Add live distance calculation via Google Maps API
  • Store real-time order data in PostgreSQL
  • Implement rate limiting and caching
  • Dockerize and deploy on GCP or AWS

Contributions

I welcome contributions to this project! If you’d like to get involved, please follow these steps:

  • Fork the repository.
  • Create a new branch for your changes.
  • Make your modifications.
  • Submit a pull request.

About

The Delivery Cost Calculator API is a backend service that determines the most cost-effective delivery option by selecting the optimal warehouse based on product weight and customer location. It helps logistics and e-commerce platforms reduce delivery costs through real-time, distance-based calculations using simple API requests.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages