What is an API? In simple term, please.

What is an API? In simple term, please.

In technical terms, API stands for Application Programming Interface . API is a software interface that allows different application components to communicate with one another.

Let's say, You want to see the trending posts on hashnode. You open the app or website and you're able to scroll through post updates and see that Victoria Lo has posted an interesting write up on how she overcame imposter's syndrome with blogging. You clicked on the post and in a split of seconds(if there's strong internet connection), the post content is displayed for you to read.

You may ask, how does this illustration applies to APIs? It applies this way: As you make the request to see Victoria Lo post, a lot of works goes on behind the scene to make it possible for you to read her post. And one of the things that makes it happen is API. And I guess there's another question on your mind, how does it work?

How APIs work

Still on Victoria Lo post, You see, hashnode server have access to all the data you want to see and for you to see it, your app (client) needs to communicate with the server and the means of communication in this case is the API. The API serves as a layer between your app and the server, taking your request to the server and fetching the response from the server back to you.

It works like this:

  • Client: I want to see Victoria Lo post on imposter's syndrome
  • Server: Here it is or It is not available for now(as the case may be)

15591453172084_requestresponse.gif

Aside this, communication can also be between server to developers or server to server.

How developer's can use APIs

There are two major ways you can use APIs as a developer in your application.

  • Private

Private API is restricted to people within an organization or application. It ensures that people outside the organization does not have access to the data from the server.

  • Public

Pubic APIs are available for public use. It allows other developers have access to data from another application to enhance their own project instead of building one from scratch. Let's say you are working as a freelance developer, and your client hope to create an outdoor event in Nigeria in the coming months. He contacted you and he wants you to build a weather app where users can get weather information in real-time. And this weather information will be a determinant if the event will hold or not. Instead of collecting your weather data, you can make use of the open weather API and get the data from there.

Aside from the main web APIs, There are also web services APIs.

Web Services APIs

A web service is a system or software that uses an address (URL) on the World Wide Web, to provide access to its services.

The following are the most common types of web service APIs:

REST

REST stands for Representational State Transfer and is a collection of architectural rules or norms that govern how data is communicated between your application and the rest of the world, as well as between different components of your application. Restful API relies on HTTP to transfer information. Some of the advantages of using REST API are:

  • There is separation between client and server which allow apps be more scalable.
  • Rest API are stateless and this makes API requests very specific and detail-driven.
  • It lets clients save data so they don't have to constantly query servers.

SOAP

SOAP stands for Simple Object Access Protocol. It is considered as a protocol and can use multiple means of communication. It requires more bandwidth which leads to slower page load times. It is used often in enterprise applications because as a developer, you can add additional layers of security, data privacy, and integrity.

XML-RPC (Remote Procedural Call)

This is a data-transfer protocol that uses a specific XML format. It supports various types of data ranging from text, numbers, images, graphs, charts etc.

Example:

<users>
  <user>
    <firstName>Victoria</firstName> <lastName>Lo</lastName>

JSON-RPC

This protocol is similar to XML-RPC but it uses JSON (JavaScript Object Notation) instead of using XML format to transfer data. It supports only text and numbers.

Example:

{"users":[
 { "firstName":"Victoria", "lastName":"Lo" },

Examples of API

  • Music APIs e.g. Spotify API
  • Payment API e.g. Paypal API, Flutterwave API
  • Weather APIs e.g. Open Weather API, Dark Sky API

If you want to start building your own APIs, Here are some resources to get you started.