Defining API

What is an API?

An API, or Application Programming Interface, provides a way for computer systems to interact with each other. There are many types of APIs. Every programming language has a built-in API that is used to write programs. Mobile devices provide APIs to provide access to location or other sensor data, such as the device's GPS location or the orientation of the device. Operating systems themselves have APIs used by programs to open files, access memory, and draw text on the screen. While the types of uses for APIs are vast, the one thing all APIs have in common is providing functionality for use by another program.

Web APIs

This book is going to focus on APIs that are built with web technologies and that work in a similar way to the web. These are often called web APIs or HTTP APIs because, like the web, they operate over HTTP. We'll use the term web APIs most often as it is shorter and potentially more common in discussion. There will be more detail about how APIs relate to HTTP as we work through the rest of this book as we delve into how web APIs work.

Provider and Consumer

When discussing APIs and how systems interact using them, distinguish between the system that the API belongs to and the external service (or user) that will use this API.

  • An API provider is the system that provides an API for other parties to use. GitHub is the provider of the GitHub API, and Dropbox is the provider of the Dropbox API.
  • An API consumer is the system that uses the API to accomplish some work. When you check the weather on your phone, it is running a program that is consuming a weather API to retrieve forecast data.

Throughout the course of this book, we will be manual consumers of the web store API. The web store server will be the provider for our initial investigation, and the following chapters will move on to working with some real world API providers.

What about Clients and Servers?

Client and server are rather overloaded terms, with server conjuring up images of racks and racks of computers in massive server farms, and clients as being small or mobile computers. In this way, client and server are often used to indicate the location or size of a computer and not its role in communicating with another machine.

When we speak of clients and servers in the context of APIs, the server is generally going to be the API provider and the client will be the consumer (technically, a client is the side of a communication that initiates the connection.) As a result of this, the terms are sometimes used as if they were synonyms.

As a result, it is best to stick to using provider and consumer when discussing APIs, as this makes the relationship of the computer to the API much clearer.

Summary

  • Web APIs allow one system to interact with another over HTTP (just like the web).
  • The system offering the API for use by others is the provider.
  • The system interacting with the API to accomplish a goal is the consumer.
  • It is best to prefer the terms provider and consumer over client and server.

With all of this terminology out of the way, let's get into why you might use an API when writing a program.