What is an API?

What is an API? What are its benefits?

In simple terms, an API (Application Programming Interface) is a mediator between two individual servers when they need to communicate with each other.

API providers typically have a set of endpoints that they offer, which gives developers access to different parts of their application or system. For example, Google has an API that lets you search through all of Google’s search results pages. Amazon also offers an API that allows you to order products from Amazon’s website.

APIs let your application communicate with other applications and services without having to know how the logic has been implemented.

Let me give you an example

Suppose you have a website and you want to show the 3 latest posts from codevocab.com. But since I don’t know who you are, I would not probably give you access to my database. But you are desperate and have requested me for the same. In spite of what I can do, I can make an API to return three recent blog posts. Doing so, your requirement will be fulfilled plus I don’t have to give you full access to my database. When you use that API, you would get the data you want.

It would look something like this-

<?php
    header('Content-Type:application/json');
    header("Access-Control-Allow-Origin: *");

    $conn = mysqli_connect("localhost", "username", "password", "mydb");
    $request_type = $_SERVER['REQUEST_METHOD'];
	
    $response = array();	

    if($request_type == 'GET'){
        $data = array();
	$query = "SELECT * FROM posts_table ORDER BY id DESC LIMIT 3";
	$res = mysqli_query($conn, $query);
		
	while($row = mysqli_fetch_assoc($res)){
	    $data[] = $row;
	}
		
	$response["message"] = "Success";
	$response['data'] = $data;
				
    }else{
        $response["message"] = "Failure";
	$response['data'] = null;	
    }
	
    echo json_encode($response);
?>

Consider that the root directory of the code file is https://codevocab.com/blogapi/ and the file name is index.php. You simply need to use this URL https://codevocab.com/blogapi/index.php and you would get the data in the form of JSON.

Note: The example code given above does not exist on my server. It was just written to make you understand the idea.

This is a very simple example of an API. You don’t have to care about the logic behind the API. All you have to use is the API endpoint and you would get the JSON data. Afterwards, you can convert that data to the format you want.

APIs have become critically important in the software development industry. Be it a mobile App, an eCommerce platform, or a social media website, APIs are everywhere.

Some more Examples

  • You can integrate a google map into your website, without hardcoding it. You just need to paste a certain code into your website and that’s it! It’s a specific API made by google which allows you to integrate a google map for your business so that your customers could easily find your office location.
  • There is another API provided by Google that allows you to let your website users to login to your website using their Google account.

One major advantage of using an API is it doesn’t matter which programming tool you have used, the API will always work for you. Considering the above example once more, my website is made with PHP, and suppose yours is made with Django, in that case also, you can consume the API.

What is an API endpoint?

API endpoints are the final touchpoints in the API communication system. These include server URLs, services, and other specific digital locations from where information is sent and received between systems.

The endpoint for the above example code would be- https://codevocab.com/blogapi/index.php

Types of API

There are four main types of APIs:

  1. Open API (Public API)
  2. Internal API
  3. Partner API
  4. Composite API
  • Open APIs: This type of API is also known as Public API. They are publicly available so there are no restrictions to access these types of APIs.
  • Internal APIs: Only internal systems offer this kind of API, which is also known as a private API. These are often made for usage inside a business or a company. The corporation uses this kind of API among its various internal teams to be able to develop its goods and services.
  • Partner APIs: These type of API are not publicly available. A developer needs specific rights or licenses in order to access them.
  • Composite APIs: This type of API combines different data and service APIs. It is a sequence of tasks that run synchronously as a result of the execution, and not at the request of a task. Its main uses are to speed up the process of execution and improve the performance of the listeners in the web interfaces.

The POSTMAN Tool (Testing APIs)

Postman is a computer program used for testing APIs, to put it simply. Postman requests something from the API, and the web server responds with whatever was requested. Requests sent and received in Postman do not require any additional labor or framework setup. It is extensively used by developers and testers to improve application testing. Simple to incorporate into your Continuous Integration (CI) and Continuous Development Pipeline.

Millions of testers use Postman because of its many capabilities and user-friendly interface. You can send requests with ease using its straightforward interface. You simply need to enter the necessary information, choose an HTTP method, and press the “Send” button. Automation is another extensively utilized¬†feature, which enables you to create test setups and test suites.

Though it is free to use, Postman offers you a paid version with pro features like multiple-user access, Control over roles, access, SSO Authentication, etc. Allowing users to set up the required environment, write specifications and finally monitor every step, is all that makes Postman an ideal Testing Tool.

How to install POSTMAN?

First, Go to https://www.postman.com/downloads/ and download it as per your system OS. Being cross-platform, it is available for Windows, Linux & Mac.

once your download is complete you can begin with installation by simply double-clicking the application.

Leave a Comment

Your email address will not be published. Required fields are marked *