This tutorial will break down what APIs really are, how they work, why they are used, and how they allow two applications to communicate with each other.
APIs- What Are They?
An API is an “Application Programming Interface” which is a software intermediary that allows two applications to communicate with each other. Many of you have used APIs before without even knowing it. Have you checked the weather on your phone? Sent a message to someone on a chat app? Chances are you were using an API to perform those tasks.
What is API Integration?
The connection between two (or more) applications, programs, services or systems is simply the integration of an API. Applications are using APIs in order to send and receive each other's data and content. Continue to read about an API history, what you are using, examples, and more.
Why Use an API?
It’s no secret that technology can and does make a lot of things in our daily lives easier but how do APIs make our lives easier? Let’s say I own a small business and I want to see if any new users have signed up on my website. I can use my API to view the details of the users. Maybe I have a marketplace application and I want to see if any new products have been added, I can use an API for that as well. APIs are very efficient in providing data. Another benefit of using an API is that they are very easy to implement into your application. It’s doesn’t matter what programming language your website or application uses or what programming language the API was built in. You can still implement its usage in your application or website.
Architecture of an API?
There are three major parts of an API:
User: This is the user who makes a request to get data from the API
Server: This is the computer that responds to the request. This is what holds the data of the API. This needs to be built first before anyone can interact with it. The server will specify an “endpoint” this is where the data can be found and will let outside programmers know where they can find the data and the structure of the API.
Client: This is the computer that sends the request to the fore-mentioned server.
History
February 7, 2000 - The first web API was introduced by Salesforce.com.
November 20, 2000 - eBay launched the eBay Application Program Interface along with the eBay Developers Program. Originally, these were only available to a selected number of licensed eBay partners.
July 16, 2002 - Amazon launched Amazon.com Web Services which allowed developers to incorporate Amazon.com features into their own websites.
API Keys
Most API’s require that you have a personalized API Key. The documentation of a particular API will explain how to get an API Key. The API key is what gives you access to the API’s data. Once you have the key you will be able to access the API’s data. if you do not obtain an API key it’s possible you won’t be able to make a successful request.
Types of APIs
There are several different types of APIs
REST API - These are the most common type of API. It follows the Representations State Transfer protocol. REST API’s take advantage of HTTP, which means developers do not need to install any type of additional libraries or additional software to take advantage of REST API design. REST API’s can return data in several different formats such as XML, JSON, YAML.
SOAP API - SOAP is a standard communication protocol system that permits processes using different operating systems such as Windows and Linux to communicate via HTTP. SOAP API’s are often used to create, recover, update and delete records such as passwords, accounts and custom objects.
OPEN API - These are often referred to as public or external API. These API’s are available for public use.
Internal API - These are used at companies internally. They allow data and tools from one group of employees to be used by other departments.
Partner API - These are similar to open APIs’ but feature restricted access. These types of API’s can often be used for specific asses like a paid membership.
Composite API - These API’s allow developers to access multiple endpoints in one API call. These could be multiple different API or multiple endpoints from the same API.
Why Do APIs Exist?
The main purpose of APIs to to provide data and allow others to access it. Think of API’s as a database of specified information.
APIs also provide an added layer of security as your device is never fully exposed to the server and the server is never fully exposed to your device. Instead, we communicate with small packets of data, sharing only what is necessary to complete the request.
It’s not uncommon for development teams to break up their application into multiple servers that talk to each other via APIs. The servers that perform helper functions for the main application server are commonly referred to as microservices. Here are some popular APIs:
Twitter
Google (Google has implemented several API’s such as Google Fonts, Google Geo-location and Google Translate)
Spotify
Vimeo
Facebook Messenger
Stripe
Building an API
I personally, have built a few APIs to interact with my applications. I will explain the process I used to build these APIs.
My first step was planning. What data do I want my API to include and how should it handle that data?
One of the APIs that I built was for a destination tracker. In this case, I would have a resource called “destinations” and nested under that would be the details of each destinations such has its name, address, features, comments etc.
To show you, in more detail what this would actually look like, see the below screenshot:
Here’s a diagram of the lifecycle of an API request.
Peer-to-Peer Communication
How are API’s important when it comes to peer to peer communication? You may not realize it but, APIs are involved in peer to peer communication when it comes to communicating electronically. Here's what Chat APIs can do -
Sending a text message.
Facebook Messenger - when you send messages via Facebook Messenger, you are using the Facebook Messenger API.
CometChat's allows users access to their API, via an interface build by developers, to create a meeting, add/remove users and more!
Summary
In this tutorial, we covered in detail what API’s are. We also discussed the different types of API’s and what types of applications offer/user API’s.
About Author
Randy is a Full Stack Software Engineer that studied at Flatiron School. My strongest technical skills are Ruby, Ruby on Rails, JavaScript, React/Redux and PostgreSQL. I enjoy learning new technologies and expanding my development skills whenever I get a chance. When my face isn’t buried in the terminal I love exploring new places, traveling, live music, and camping.
Key resources to learn more about APIs
API Keys - CometChat Pro Documentation
Here’s Everything You Need to Know About A Chat API!
Randy Steele
CometChat