We built an API to calculate flight Co2 emissions

We built an API to calculate flight Co2 emissions
Laura Marshall Nyble
Mihai Muntean
Author
April 29, 2021
Published
DEV

Our guide to reducing your Co2...API response times

In our previous post, we mentioned that we displayed CO2 emissions to users of an iPad application that we developed. The requirement was for Nyble to calculate the carbon footprint for air business travel based on the origin, destination and class of travel chosen. We saw that there was likely to be a need for this information in different use cases, our iPad app but also future web applications from Nyble and others. Initially we assumed someone must have made this before, indeed they had but there were surprisingly few solutions available on the internet. Those that were available had slow response times, were not fit for purpose or charged for use with no demo option available. We decided to build our own.

Our self-set requirements for the API:

  • 50ms 95th percentile response time
  • All raw data required for carbon emissions must be available via the API as well (such as airports, travel classes etc)
  • The API should be RESTful and easy to use
  • Hosting has to be cheap/free – otherwise we could just use a paid API

As a standard approach we tend to use Google Cloud Platform (“GCP”) before considering any other options (although we have extensive experience with Azure Cloud as well). Keeping this in mind and considering that this kind of API does not seem like it would be used very often we decided to make use of the free 28 hours of “F” instances per day. This being the least powerful instance class on GCP, it limited the options we had for the stack to power our API, hence we decided to go (pun intended) for Golang and Firestore. This stack is quick and lightweight – exactly what we needed.

The API documentation can be accessed here.

Although there is no pricing involved with using the API, you have to get in touch with us to get a key – please use the “Contact Us” form and enjoy!