Coder Social home page Coder Social logo

flight-api's Introduction

PowerUs Flights

Setup

You need to install NodeJS on your machine. For the best experience VSCode is also recommended. To install the repositories dependencies run

npm i

API

The core part of this repository is the PowerUs Flights API which provides an endpoint to receive flight data from several sources. You can run the server with the command

npx nx run flights:serve

which means that we run the serve target of the flights app. The configuration for the app is available in the project.json. The server is then available under http://localhost:3333/api.

API Interaction

To test the API manually, you can either open your browser and type http://localhost:3333/api/flights, which performs an HTTP get request to that URL. Or you install the VSCode extension Thunder Client and import the collection saved under ./tools/powerus-flights-api-collection.json.

API Debugging

Start the app as usual. Navigate to the VSCode debugger, select Attach to NestJS API and run it. The debugger is configured in a way that it auto attaches when the app is served and refreshes on save.

API Details

The flights endpoint works in the following way: When a request to the GET /api/flights endpoint is triggered, the server requests ressources for each of the available endpoints. The endpoints can be defined in the environment files of the API. For each individual request it checks if there is an existing and valid (by time to life) in the cache. If that's true, it returns the cache entry. Otherwise it makes the request to the endpoint with a retry strategy of 3 times (because the endpoints are not stable). When the response arrives, it validates the response, and formats it into a suitable format for a list of flights (for each flight having an ID for example). Once this is done, the request gets stored in the cache.

When all of the individual requests are ready to be processed, they will be merged with removed duplicates and returned to the client. The following diagram should visualize the whole process. With this strategy in place it is unlikely that an endpoint completely fails and the users will face "longer" requests only once every time a cache expires (every hour). If there is constant traffic, a significant amount of users will hit the cache and get quick responses.

./docs/api-flow-chart.svg

flight-api's People

Contributors

ngfelixl avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.