Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Mock Delivery API

A Node.js + Express mock API for testing, learning, and API documentation practice.

  • Uses static data (no database)
  • All write operations (POST, PATCH, DELETE) return success but do not persist
  • Supports pagination, filters, tracking, reports, assignments

Server runs on:

http://localhost:4000

Authentication:

Authorization: Bearer testtoken123

Getting Started

npm install
npm start

Random Error Simulation

GET list endpoints (/deliveries, /drivers, /parcels, /hubs) have a 10% chance to return:

{ "error": "Random simulated error" }

Authentication flow

All API endpoints (except login) require authentication. Follow the steps below to access protected resources.

Step 1: Log in to obtain an access token

Call the login endpoint with a username and password to receive an access token.

Request

POST http://localhost:4000/auth/login
Content-Type: application/json

Request body

{
  "username": "demo",
  "password": "demo"
}

Response

{
  "token": "testtoken123",
  "user": "mock-user"
}

Step 2: Use the token for all subsequent requests

Include the token in the Authorization header for every API request.

Example: Get deliveries

GET http://localhost:4000/deliveries
Authorization: Bearer testtoken123

If the Authorization header is missing or invalid, the API will return a 401 Unauthorized response.

πŸ“„ Pagination

All list endpoints support query parameters:

Query Default Description
page 1 Page number
limit 10 Items per page

Endpoints Overview

Below is a complete list of 70+ endpoints, grouped by category, including POST examples.


1 Authentication

  1. POST /auth/login – login and get token

Sample Request

{
  "username": "demo",
  "password": "password123"
}

Response

{
  "token": "testtoken123",
  "user": "mock-user"
}

2 Deliveries

  1. GET /deliveries – list deliveries (supports status, city, country)
  2. GET /deliveries/:id – get single delivery
  3. POST /deliveries – create delivery

Sample Request

{
  "status": "pending",
  "address": "22 Hill View Estate",
  "customer": "Mary James",
  "parcelId": 12,
  "driverId": 3,
  "city": "London",
  "country": "UK",
  "date": "2025-12-07"
}
  1. PATCH /deliveries/:id – update delivery
  2. DELETE /deliveries/:id – delete delivery
  3. GET /deliveries/status/:status – filter by status
  4. GET /deliveries/city/:city – filter by city
  5. GET /deliveries/country/:country – filter by country
  6. GET /deliveries/customer/:customer – filter by customer
  7. GET /deliveries/date/:date – filter by date
  8. GET /deliveries/range/:start/:end – filter by date range

3 Drivers

  1. GET /drivers – list drivers (supports vehicle, state, country, carModel)
  2. GET /drivers/:id – get single driver
  3. POST /drivers – add driver

Sample Request

{
  "name": "David Okoro",
  "vehicle": "Bike",
  "carModel": "Volvo",
  "state": "California",
  "country": "USA",
  "availability": "available",
  "experience": 5,
  "rating": 4.7
}
  1. PATCH /drivers/:id – update driver
  2. DELETE /drivers/:id – delete driver
  3. GET /drivers/state/:state – filter by state
  4. GET /drivers/country/:country – filter by country
  5. GET /drivers/vehicle/:vehicle – filter by vehicle
  6. GET /drivers/car/:carModel – filter by car model
  7. GET /drivers/availability/:status – filter by availability
  8. GET /drivers/experience/:years – filter by experience
  9. GET /drivers/rating/:min – filter by rating

4 Parcels

  1. GET /parcels – list parcels (supports description, weightMin, weightMax)
  2. GET /parcels/:id – get single parcel
  3. POST /parcels – create parcel

Sample Request

{
  "weight": 3.5,
  "description": "Laptop Accessories",
  "deliveryId": 10,
  "destinationHubId": 4
}
  1. PATCH /parcels/:id – update parcel
  2. DELETE /parcels/:id – delete parcel
  3. GET /parcels/description/:description – filter by description
  4. GET /parcels/weight/min/:min/max/:max – filter by weight range
  5. GET /parcels/weight/min/:min – filter by min weight
  6. GET /parcels/weight/max/:max – filter by max weight
  7. GET /parcels/delivery/:deliveryId – filter by delivery
  8. GET /parcels/hub/:hubId – filter by destination hub

5 Hubs

  1. GET /hubs – list hubs (supports city, country, capacityMin, capacityMax, region)
  2. GET /hubs/:id – get single hub
  3. POST /hubs – create hub

Sample Request

{
  "city": "Manchester",
  "country": "UK",
  "capacity": 200,
  "region": "Northwest"
}
  1. PATCH /hubs/:id – update hub
  2. DELETE /hubs/:id – delete hub
  3. GET /hubs/city/:city – filter by city
  4. GET /hubs/country/:country – filter by country
  5. GET /hubs/capacity/min/:min/max/:max – filter by capacity range

6 Reports

  1. GET /reports/deliveries/status – count deliveries by status
  2. GET /reports/drivers/vehicle – count drivers by vehicle
  3. GET /reports/parcels/type – count parcels by type
  4. GET /reports/hubs/capacity – list hub capacities

7 Assignments

  1. POST /assignments/delivery/:deliveryId/driver/:driverId – assign driver to delivery
  2. GET /assignments/driver/:driverId – get deliveries assigned to driver
  3. GET /assignments/hub/:hubId – get parcels assigned to hub

8 Tracking

  1. GET /tracking/delivery/:deliveryId – delivery tracking
  2. GET /tracking/parcel/:parcelId – parcel tracking

πŸ“„ Example cURL Commands

# Login
curl -X POST http://localhost:4000/auth/login \
 -H "Content-Type: application/json" \
 -d '{"username":"demo","password":"password123"}'

# Create a delivery
curl -X POST http://localhost:4000/deliveries \
 -H "Content-Type: application/json" \
 -H "Authorization: Bearer testtoken123" \
 -d '{"status":"pending","address":"22 Hill View Estate","customer":"Mary James","parcelId":12,"driverId":3,"city":"London","country":"UK","date":"2025-12-07"}'

# Add a driver
curl -X POST http://localhost:4000/drivers \
 -H "Content-Type: application/json" \
 -H "Authorization: Bearer testtoken123" \
 -d '{"name":"David Okoro","vehicle":"Bike","carModel":"Volvo","state":"California","country":"USA","availability":"available","experience":5,"rating":4.7}'

# Add a parcel
curl -X POST http://localhost:4000/parcels \
 -H "Content-Type: application/json" \
 -H "Authorization: Bearer testtoken123" \
 -d '{"weight":3.5,"description":"Laptop Accessories","deliveryId":10,"destinationHubId":4}'

# Add a hub
curl -X POST http://localhost:4000/hubs \
 -H "Content-Type: application/json" \
 -H "Authorization: Bearer testtoken123" \
 -d '{"city":"Manchester","country":"UK","capacity":200,"region":"Northwest"}'

# Assign driver
curl -X POST http://localhost:4000/assignments/delivery/10/driver/3 \
 -H "Authorization: Bearer testtoken123"

βœ… Notes

  • All POST/PATCH/DELETE endpoints always return success
  • No data is stored β€” everything resets on server restart
  • Supports filters, pagination, random errors, reports, assignments, and tracking

This lists all endpoints (70+ when counting filter GETs) with POST examples included.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages