This project is a JSON over HTTP API endpoint that calculates the shortest route between two airports, given their IATA codes. It returns the shortest route based on the geographical distance in meters.
The API is designed to find a route between two airports with the following constraints:
- The route can consist of at most 4 legs/flights (e.g., A->1->2->3->B or A->1->B).
- The route should be the shortest in terms of geographical distance (in kilometers).
The API also allows changing airports during layovers within a 100km radius. For example, A->1->2=>3->4->B, where "2=>3" is a change of airports done via ground transportation. These switches are not considered part of the legs/layover/hop count, but their distance should be reflected in the final distance calculated for the route.
This service utilizes the following data sources:
- Flight Route Database from Kaggle, last updated in 2017
- Airports Geospatial Database from Kaggle, last updated in 2022
Please be aware that the provided routes may no longer be valid due to the age of the flight route data. The service is intended for informational purposes only and should not be relied upon for up-to-date flight planning or navigation.
Before you begin, ensure you have met the following requirements:
- You have a Windows/Linux/Mac machine running the latest version of your preferred operating system.
- You have installed Node.js version
18.x.x
or higher. To check your Node.js version, runnode -v
in your command line. - You have installed npm version
8.x.x
or higher. To check your npm version, runnpm -v
in your command line.
To set up the project, follow these steps:
- Clone the repository.
- Navigate to root
npm install
npm run build --workspace @airport-routes/server
npm run start --workspace @airport-routes/server
Optional. If you want to update data used by service,
- Update
packages\build-graph\input-data\routes.csv
andpackages\build-graph\input-data\airports.csv
with relevant data. npm run build --workspace @airport-routes/build-graph
npm run build-graph --workspace @airport-routes/build-graph
- Restart the server.
To run tests:
npm run test --workspace @airport-routes/server
Send a GET
request to the /calculate
endpoint with the following query params:
{
"source": "IATA code of the origin airport",
"target": "IATA code of the destination airport"
}
Route: Los Angeles International Airport to Milwaukee County's Timmerman Airport
URL: /calculate?source=LAX&target=MWC
Example response:
{
"start": "LAX",
"finish": "MWC",
"distance": 2845099,
"path": [
{
"means": "AIR",
"from": "LAX",
"to": "MKE",
"distance": 2823750
},
{
"means": "GROUND",
"from": "MKE",
"to": "MWC",
"distance": 21349
}
]
}
Route: Nuuk Airport to Easter Island Mataveri International Airport
URL: /calculate?source=GOH&target=IPC
Example response:
{
"start": "GOH",
"finish": "IPC",
"distance": "Infinity",
"path": []
}
-
Longyearbyen Airport to Ulaanbaatar Chinggis Khaan International Airport
-
Cochabamba Jorge Wilstermann International Airport to Hargeisa Egal International Airport
-
Nuuk Airport to Chittagong Shah Amanat International Airport
-
La Paz El Alto International Airport to Krasnoyarsk Yemelyanovo International Airport
This project is open-source and available under the MIT License.