Here is a detail doc for the format of the API endpoint
The created RESTful API for Flight Path Tracker as a microservice helps track and determine a passenger's flight path based on a list of unordered pair(s) of flight records, source and arrival points. On a broader sense, the API accepts a request that contains a list of flights defined by source and destination airport codes (IATA), sorts them, and returns the complete, compact, and viable flight path from take-off to the destination arrival airports.
A. Tools Used and Steps of Development :
-
Created a specified folder
JavaScript Flight Path Tracker
on local machine, H:/ -
Opened VS Code via command terminal in the specified folder
-
Initialized the project via
bash
terminal running the following commandsmkdir flight-path-tracker
cd flight-path-tracker
npm init -y
Which follows the following on the VS code terminal prompt: HP@DESKTOP - 9LVHOGF MINGW64 /h/JavaScript Flight Path Tracker/flight-path-tracker
-
Installed 2 following packages using the command below: express and body perser
npm install express body-parser
-
Created flight path sourcing logic on
findFlightPath.js
on the same directory -
Created server with express js and set up the
/calculate
API endpoint onserver.js
B. Running the server locally (pre-testing)
-
Installation of the dependancy
npm
onbash
terminal using the below command:npm install
-
Starting the server:
node server.js
-
'Flight path tracker listening on port 8080' appears as follows:
- Content Type: 'application/json'
- Body: 'Flights' contains an array of records as pair(s) in IATA format
- Content Type: 'application/json'
- Body: A JSON array with sorted, and compact flight path (as tested and shown below in 'Testing' section)
Checked for various invalid formats, i.e., 'flights' should be of two elements, start and end.
- Sample error message: 'Invalid input format. Expected an array of flight records.'
Checked the performance of API on Postman locally and it worked as expected for different use cases and scenarios:
Airports and cities I typically stepped in taking multiple flights: It worked amazingly as expected!
-
On Postman, locally installed: name the project or request to be made
-
'New' > Select 'POST' > Enter URL 'http://localhost:8080/calculate'
-
'Body' > 'raw' & 'JSON'
{ "flights": [ ["ATL", "EWR"], ["SFO", "ATL"] ] }
With various use cases, this JSON format changes.
- Clicking the 'send' outputs the following, as expected: ["SFO", "EWR"]
Tested for various use cases, for example: the direct, multiple, and complex flights.