What is the Clear Definition of an API?
Tags: ruby, javascript, react, graphql
Published: 2020-12-16 04:52:31

When you search for the definition of an API online, there will be some very ambiguous results. I found myself and many others a bit confused when it came to the explanations provided.

I will explain a little bit of how various entities use the term API below but if you would just like the straight answer, jump [**here**](#straight-forward-api-definition)

## What is an API? 

As an overview, I was taught that an API is a way for one system to communicate with other external systems. Let's define more of what an API is.

The Wikipedia definition of an API is:

> An *Application Programming Interface* (API) is a computing interface that defines interactions between multiple software intermediaries.

- An [*Application*](https://en.wikipedia.org/wiki/Application_software) is a program or a group of programs designed for an end-user (a user that is intended to use the application)
- *Programming* is the process of creating a set of instructions that tell a computer how to perform a task.
- An [*Interface*](https://en.wikipedia.org/wiki/Interface_(computing)) is a shared boundary across which two or more separate components of a computer system exchange information.

You've probably seen various entities use the term API. Let's see some examples:

1.) [React.js](https://reactjs.org/docs/react-api.html)

At the very top of the page:

> React is the entry point to the React library. If you load React from a script tag, these top-level APIs are available on the React global. If you use ES6 with npm, you can write import React from 'react'. If you use ES5 with npm, you can write var React = require('react').

2.) [Ruby on Rails API](https://github.com/rails/rails)

Ruby on Rails is a web-application framework that includes everything needed to create database-backed web applications according to the Model-View-Controller (MVC) pattern.

When you navigate to the GitHub link above for the Ruby on Rails repo and scroll down to the bottom, you'll see a link for the Ruby on Rails [API Documentation](https://api.rubyonrails.org/).

> API documentation is a technical content deliverable, containing instructions about how to effectively use and integrate with an API

3.) [Graphql](https://graphql.org/learn/)

> GraphQL is a query language for your API, and a server-side runtime for executing queries by using a type system you define for your data. GraphQL isn't tied to any specific database or storage engine and is instead backed by your existing code and data.

4.) [Google APIs](https://en.wikipedia.org/wiki/Google_APIs)

> Google APIs are application programming interfaces developed by Google which allow communication with Google Services and their integration to other services.

5.) [The Twitter API](https://developer.twitter.com/en/docs)

> The Twitter API enables programmatic access to Twitter in unique and advanced ways. Use it to analyze, learn from, and interact with Tweets, Direct Messages, users, and other key Twitter resources.

6.) [Using Ruby on Rails as an API](https://guides.rubyonrails.org/api_app.html)

> Traditionally, when people said that they used Rails as an "API", they meant providing a programmatically accessible API alongside their web application.

---

**In all of these cases, one entity interacted and outputted a result to a separate entity.**

All the definitions and examples above still didn't give a straight forward answer as to what an API actually *is*. 

The definition of an *interface* is a shared boundary across which two or more separate components of a computer system exchange information. Let's use React as an example. 

What is React.js? A JavaScript library for building user interfaces.

> A library is a collection of programs and software packages made generally available, often loaded, and stored on disk for immediate use.

> A user interface is the space where interactions between humans and machines occur.

> The *graphical user interface* (GUI) is a form of user interface that allows users to interact with electronic devices through graphical icons and audio indicators such as primary notation, instead of text-based user interfaces, typed command labels, or text navigation.

> A *command-line interface* (CLI) processes commands to a computer program in the form of lines of text.

Essentially, React is used to create a way in which users can interact with the browser and/or other frameworks, such as Gatsby.js.

> A web application (or web app) is application software that runs on a web server, unlike computer-based software programs that are run locally on the operating system (OS) of the device.

> Web applications are accessed by the user through a web browser with an active internet connection.

### Straight Forward API Definition

So what is the clear-cut definition of an API?

The Application Programming Interface is a programmatic interface. A programmatic interface is literally the code utilized in interacting with another program that has its own special methods, functions, and syntax.

For example, let's write a class component with React:

```js
import React, { Component } from 'react';

export default class myComponent extends Component {
  render(){
    <h1>React Component Header</h1>
  }
}
```

React uses a declarative programming style. This means you programmatically declare what the program should do, *but* **you don't explicitly define how the program will do it**.

The React functions, methods, syntax, and rules for a component is the interface we utilized in order to interact with the browser. **`Component` doesn't show us what it does under the hood**.

The API of React is its syntax and features. **You will use its syntax and features to interact with another program**, typically the browser.

---

Thank you for reading!