Jordan Uses aviationstack
Tags: apilayer, aviationstack, javascript, typescript
Published: 2020-01-15 20:16:48

---
title: Jordan Uses aviationstack
published: true
date: 2020-01-06 15:25:40 UTC
tags: apilayer,aviationstack,Javascript,Typescript
canonical_url: https://javascriptwebscrapingguy.com/jordan-uses-aviationstack/
---

[Demo code here](https://github.com/aarmora/jordan-uses-aviationstack)

_This is a sponsored blog post by positionstack. All reviews and opinions expressed here are, however, based on my personal experience_.

This is my fourth post about APIs created by [apilayer](https://apilayer.com/). The other three were for [scrapestack](https://javascriptwebscrapingguy.com/jordan-scrapes-with-scrapestack/) (for proxying any and all web requests), [serpstack](https://javascriptwebscrapingguy.com/serpstack-easy-search-engine-results/) (for getting search engine results in a quick and easy JSON format), and [positionstack](https://javascriptwebscrapingguy.com/jordan-uses-positionstack/) (geocode location). I’m still really impressed with their APIs, with full featured documentation on their positionstack product [here](https://aviationstack.com/documentation).

## We fly!

![gandalf fly you fools gif](https://media.giphy.com/media/A6PcmRqkyMOBy/giphy.gif)

Aviationstack starts out with a lot of information. My first query to the base /flights route took a while just to handle all of the responses. There are a lot of flights happening in the world! This is what I started with:

```
	// See how many total we get
	const axiosResponse = await axios.get(`${baseUrl}/flights?access_key=${process.env.apiKey}`);

	console.log('response', axiosResponse.data.pagination.total);
```

Getting the total at this point in time turned out to return 413,374 flights. I just ran it again 30 seconds later and now it’s at 413,380. So it’s updating in real time as additional flights are scheduled.

Fear not! As with all of apilayer’s APIs, aviationstack is fully featured with a lot of refinement options, including limit and offset. Check a screenshot of some of the results:

![aviationstack results with limit and offset](https://javascriptwebscrapingguy.com/wp-content/uploads/2020/01/image.png)

While it is cool to see all of this cool information, including the gate, scheduled time, deparature, and arrival airport, it’s still a LOT of information. I wanted to try aviationstack in some ways that were useful to me.

## Personal uses

![christian bale personal gif](https://media.giphy.com/media/MWj6Dl3GbW2By/giphy.gif)<figcaption>This is what returned for personal. And I like Christian Bale.</figcaption>

I live in Boise, Idaho. It’s not a very big place (though [it keeps growing](https://www.businessinsider.com/boise-idaho-fastest-growing-city-in-us-photos-growth-cost-2019-12)!) and the airport doesn’t fly a ton of places. Sometimes when I’m scheduling flights it’s kind of ridiculous what I have to do to go somewhere other than Salt Lake City and Seattle. It can make flying a pain.

So, I decided to see for real what airports Boise is flying to over the next few days. My code looked something like this:

```
	// Get airports Boise flies to
	const axiosResponse = await axios.get(`${baseUrl}/flights?access_key=${process.env.apiKey}&dep_iata=boi`);

	const airportsBoiseFliesTo: any[] = [];

	for (let flight of axiosResponse.data.data) {
		if (airportsBoiseFliesTo.indexOf(flight.arrival.airport) < 0) {
			airportsBoiseFliesTo.push(flight.arrival.airport);
		}
	}

	console.log('airports boise flies to', airportsBoiseFliesTo);
```

Aviationstack allows you to pass in a `dep_iata` query parameter which is a departure airport code. They also provide API endpoints for both [airports](https://aviationstack.com/documentation#airports) and [cities](https://aviationstack.com/documentation#cities) which would help us get our airport code if we needed it. In order to take advantage of the search query parameter, however, you have to be on at least the basic plan.

Here’s the response of that query:

![aviationstack results for airports that boise flies to](https://javascriptwebscrapingguy.com/wp-content/uploads/2020/01/image-1.png)

Okay, so I’m pretty close on my assessment of Boise’s airport choices. Due to its size, Boise has to fly to a regional hub before flying out to anywhere else. Louisville and the airports in Texas were a bit of a surprise to me. Pretty neat.

## Upgraded plan endpoints

Aviationstack offers a lot of additional power at their higher plans. These include things like:

[Historical data](https://aviationstack.com/documentation#historical_flights). You give it a date in the past and it’ll return all the flight information for that date.

[Airline routes](https://aviationstack.com/documentation#airline_routes). This is updated every 24 hours and and offers the full route information. Like this:

![aviationstack airline route information](https://javascriptwebscrapingguy.com/wp-content/uploads/2020/01/image-2.png)

The API is extremely robust. A lot of information and it’s very easy to use. The price is very reasonable, as with all of apilayer’s APIs.

![aviationstack pricing](https://javascriptwebscrapingguy.com/wp-content/uploads/2020/01/image-3-1024x541.png)

[Check it out](https://aviationstack.com/)!

The post [Jordan Uses aviationstack](https://javascriptwebscrapingguy.com/jordan-uses-aviationstack/) appeared first on [JavaScript Web Scraping Guy](https://javascriptwebscrapingguy.com).