Introduction to APIs and Web APIs for beginners

Introduction to APIs and Web APIs for beginners

Basics

Before we start with 'What is an API?', it is important for us to understand certain jargons. If you are familiar with client and server concepts, feel free to skip this section.

  • A client is a program capable of communicating with a server/s, mainly to ask for information (request) that it requires.
  • A server is another program capable of communicating with a client/s, mainly to provide information (response) that it is being asked for.

client-side-scripts-server-side-scripts.png

  • When you say something is on the Client-Side, this means it is executing on your machine.
  • When you say something is on the Server-Side, this means it is executing on another machine (like a remote machine on the internet).

  • Frontend refers to code written on the Client-Side.

  • Backend refers to code written on the Server-Side.

  • A Web Browser is an example of a client (also called frontend service).

  • A Database Server is an example of a server (also called backend service).
  • Connecting the terms: The Web Browser (client) executes some code on the Client-Side, and sends a request to a Database Server (server) that will execute some other code on the Server-Side.

Introduction

With the foundation laid, let us now finally discuss APIs.

Big Question: What is an API?

  • API stands for Application Programming Interface.
  • In simple terms, an API is a helper which takes in the request of the client and gives it to the server.
  • Once the server returns the response, it gives it back to the client. Thus, the client actually sends/receives data to/from an API (using the HTTP protocol) and not directly to/from the server.
  • The best way to explain the use of an API is the classic restaurant example, wherein the customer acts as the client, the waiter acts as the API and the kitchen acts as the server. When the customer orders food, he/she never communicates with the kitchen directly, but only through the waiter. Once the food is ready, the kitchen informs the waiter and the waiter delivers it to the customer.

api example.jpg

  • In general, any software library or even the interface an OS provides to applications is considered an API. Even a small function in code can be considered an API. But in web development, when we speak about API, we mean web APIs.

What is a web API?

  • Web APIs are usually associated with the backend. That's why we also refer to them as backend APIs.
  • These web APIs help developers interact with backend services (like a server).

Types of Web APIs

-> In terms of the architecture, they can be classified into:*

  • REST API
  • SOAP API
  • GraphQL API
  • RapidQL API
  • Kafka API

All the above types mentioned provide a different mechanism/channel of communication between systems or computers on the internet.

-> In terms of the accessibility, they can be classified into:*

  • Public/Open APIs: Anyone can access this API. Eg: Weather API, Twitter API
  • Partner APIs: Needs a specific licence/s to access it. Eg: An API provided by a company to its clients.
  • Private/Internal APIs: Only certain people can access this. Eg: An API provided by a company to its employees.