No history yet

Introduction to Web APIs

What is an API?

Think about ordering food at a restaurant. You don't go into the kitchen to tell the chef what you want. Instead, you give your order to a waiter. The waiter acts as an intermediary, communicating your request to the kitchen and bringing the food back to your table. In the world of software, an API, or Application Programming Interface, is the waiter.

An API is a set of rules and protocols that allows different software applications to communicate with each other.

It's a contract that defines how a developer can request information or functionality from another piece of software. You don't need to know how the kitchen works to get your meal, and a developer doesn't need to know the inner workings of an application to use its API. They just need to know how to make the right requests.

This ability for different systems to talk to each other is called interoperability. APIs are the foundation of this concept, making it possible for thousands of separate applications to connect and share data, creating the interconnected web experience we use every day.

Lesson image

Web APIs in Action

When an API works over the internet, we call it a Web API. It uses the web's communication protocol, HTTP, to send requests and receive responses. This is how a weather app on your phone gets up-to-the-minute forecasts or how a travel website can show you flight options from hundreds of different airlines at once.

Let's stick with the travel website. When you search for a flight from New York to London, the website's front-end (what you see in your browser) sends a request to its own back-end server. That server then uses the APIs of various airlines to ask, "What flights do you have available from JFK to LHR on this date?" Each airline's system processes the request, finds the relevant data in its database, and sends a response back through its API. The travel site's server gathers all these responses and presents them to you in a single, organized list.

APIs work by defining a set of requests and responses that allow software systems to exchange information – without needing to know how the other system is built.

This request-response cycle is the fundamental interaction model for most Web APIs.

Two Sides of the Coin

Web APIs can be broadly categorized into two types: client-side and server-side. The distinction is all about where the API lives and what it provides access to.

Client-side APIs are built directly into your web browser.

They aren't used for fetching data from a remote server. Instead, they give web developers programmatic access to the browser's own features and the computer it's running on. For example, the Geolocation API allows a website to ask for your location to find nearby points of interest. The DOM (Document Object Model) API lets JavaScript change the content and appearance of a web page after it has loaded.

Client-side Web APIs are built into web browsers and allow web pages to perform complex tasks by accessing system resources or external data.

Server-side APIs, on the other hand, run on a remote server. These are the APIs we discussed in the travel website example. They act as a public-facing gateway to a server's resources. When a company like Twitter or a weather service wants to allow other developers to access their data or functionality, they create a server-side API. Developers can then send requests to this API over the internet to get tweets, weather data, or perform other actions.

API TypeLocationPurposeExample
Client-SideIn the web browserAccess browser featuresGeolocation API to find your position
Server-SideOn a remote serverAccess an application's dataTwitter API to fetch recent tweets

Both types are essential for modern web development. Client-side APIs help create rich, interactive user experiences, while server-side APIs enable the data sharing that powers complex, multi-service applications.

Quiz Questions 1/5

In the restaurant analogy used to describe how software components interact, what role does the API (Application Programming Interface) play?

Quiz Questions 2/5

The ability for different, separate software systems to connect and share data with each other through APIs is known as: