Implemented a microservice that will expose an API endpoint /calculate that accepts flight records, sorts them, and returns the start and end destinations of the flight path.
This microservice tracks a person's flight path by sorting through their flight records.
Sample Request:
- URL:
/calculate
- Method:
POST
- Content-Type:
application/json
- Body:
{ "flights": [ ["ATL", "EWR"], ["SFO", "ATL"] ] }
Response:
- Content-Type: application/json
- Body:
["SFO", "EWR"]
Running the Server
-
Open terminal and navigate to project folder:
cd flight-path-tracker/
-
Install dependencies:
npm install
-
Start the server:
node server.js
-
The server will be running on http://localhost:8080
-
One a new terminal to run the test cases using following curl commands:
curl -X POST http://localhost:8080/calculate -H "Content-Type: application/json" -d '{"all_flights": [["SFO", "EWR"]]}'
curl -X POST http://localhost:8080/calculate -H "Content-Type: application/json" -d '{"all_flights": [["ATL", "EWR"], ["SFO", "ATL"]]}'
curl -X POST http://localhost:8080/calculate -H "Content-Type: application/json" -d '{"all_flights": [["IND", "EWR"], ["SFO", "ATL"], ["GSO", "IND"], ["ATL", "GSO"]]}'
Interesting Ideas and Scalability
- This service can be scaled horizontally by deploying it behind a load balancer.
- Frequently queried flight paths can be cached to improve performance.
- Authentication can be implemented to restrict access to the API.
- Improved error handling to provide more detailed messages.