What is an API?

Build web apps with NodeJS & Express

🕑 This lesson will take about 10 minutes

API stands for Application Programming Interface. An API is an interface that defines the interactions that can occur between different software applications such as the kinds of calls or requests that can be made, how to make requests/calls, the data formats that responses should be represented with, and the rules or conventions to follow.

There are many different web APIs that allow you to use services or fetch different types of data that can be used within your application. For example, if you were building a weather app, you wouldn't need to build your own weather stations around the world to get weather conditions data such as temperature and humidity for every city. Instead, you could fetch data from an existing weather service’s API by making requests for weather data for particular cities, for example. You can customise the type of data you want from the request too, for example, you might request daily maximum and minimum temperature forecasts for a particular city for the next 7 days.

Likewise, if you were making a shopping app and you wanted to get real-time currency conversion rates, you could use an API to find out the current conversion rate between two currencies. There are so many web APIs that provide a range of different services and data - some are completely free, some are free depending on how many requests you're going to make, and others can be accessed through a paid subscription.

A web API works by:

  • making a request and specifying parameters in the request (your application sends the request to the API and specified parameters in the request eg. current temperature in degrees Celcius for the location Sydney, Australia)

  • getting a response (retrieving the requested data in a particular format eg. represented in JSON format)

  • extracting the information to be used from the response

In the next few lessons, we will look at how to make API requests, how to extract information from a response and work with JSON data, and how to then use that data in an app. We will make a small weather app using the free version of the OpenWeatherMap API.

Next lesson: Making API requests