Online College Courses for Credit

+
Definition of API

Definition of API

Rating:
(0)
Author: Devmountain Tutorials
Description:

Identify the concept of an interface such as Application Programming Interface, or API.

(more)
See More
Tutorial
what's covered
This section will explore Application Programming Interface (API) by discussing:
  1. DEFINITION OF API
  2. API EXAMPLE

1. DEFINITION OF API

As we saw in the last challenge, an algorithm collects different sets of information, also known as data, and puts it together to make a decision for the user.

Think about the somewhat obsolete work of a travel agent. She begins with what she knows about her clients’ travel preferences – where they would like to go, what they like to do, and their preferred mode of travel.

Thus begins her travel algorithm: she pulls information from the best airline companies and tour companies. She selects flights and tourist activities for her clients. Depending on airlines’ availability, she makes necessary adjustments to tourist activities. Depending on her travel agency’s partnerships, she applies available discounts to airlines and activities. All of this work encompasses the algorithm of the travel agent. It’s complex work that can be done in a variety of ways.

Nowadays, we are our own travel agents. We don’t need specialized agents to call airline companies or tell us about the available activities for a certain city we’ve never been to. That data is available to us directly through the internet.

We are able to interact with the raw source of the information to make our own complex set of decisions. In this analogy, the interface that we humans use to get data about airline flights is not unlike an API, or an Application Programming Interface.

As we know, algorithms are now being completed by computers, and computers need a way to talk to their own data sources. Computers need to be able to pull in different sets of data just like a travel agent would back in the old days.

f you recall from Units 1 and 2, API stands for Application Programming Interface. But, the acronym doesn’t really provide enough information to understand what an API means to a web developer. An API is the set of options a computer (or code) has to be able to use to talk to an external data source. In this challenge, we'll get to explore API's and their importance a little more.


2. API EXAMPLE

The API for an airline flight data source would be composed of a set of methods, or functions, that are each a unique question that the computer code can “ask” the data source.

For example, the code might execute the method flight_search to ask the question “Can I have a list of all direct flights from San Francisco to Lisbon that leave on February 20, 2021?” and the data source would respond with that list.

It’s important to note that API refers to the interface for the data—not the data itself. When we think about APIs, we are thinking about the set of questions, or methods, that we are able to use to speak to a dataset.

As programmers, we might not have direct access to a database with the data that we want. The reasons for this are simple—we don’t maintain the database of flight information. Instead, there is some external entity that has that responsibility. If we did have direct access to the flight database, we could query it using SQL, the language of databases.

Instead, the programmers who maintain the flight data have exposed their data to external programmers who may want to use it via an API. Below, you can see an example of the API for the flight data. We use the API by installing a code package and then writing code according to the API’s documentation.

Here is an example of what the documentation might look like for the flight data API.

Image of a chart that shows the request, parameters, and response returned as if it was a functioning API for flight information.
Sample API: Flight Data

As you can see, there are three methods in this excerpt of API documentation. Think of each method as a question that we can ask the database.

Methods can take parameters, or additional pieces of data that change the question we’re asking. Some parameters are required in order to use the method, while some are optional and can be provided to narrow the set of data that you’re asking for.

terms to know

Interface
A way for two systems to interact.
Method
A question that we can ask the database.
SQL
The language of databases.

Terms to Know
Interface

A way for two systems to interact.

Method

A question that we can ask the database.

SQL

The language of databases.