Understanding API Concepts

In the fast-paced world of software development, APIs (Application Programming Interfaces) have become the backbone of modern applications. They allow different systems to communicate and work together without any trouble. As a software tester, you need to understand and test APIs well to make sure that the software environment is reliable and works well. In this article, we will learn what is API, the Type of APIs, What is API testing & some popular tools we can use for API testing.

What is API?

API stands for Application Programming Interface. It is a set of defined rules that enable different applications to communicate with each other. It acts as an intermediary layer that processes data transfers between systems, letting companies open their application data and functionality to external third-party developers, business partners, and internal departments within their companies.

API Example

As you can see in the picture, API is like a connector, All data connect to the organization through API.

Example

We can understand API better through a restaurant example. Suppose we are in a restaurant.

API Example

API is the messenger that takes your order (waiter) and tells the system (Kitchen/Chef) what to do (to prepare food) and in return gives back the response you asked for (waiter returns with the ordered food).

Type Of APIs

REST

The representational state transfer (REST) architecture is probably the most popular way to build APIs. REST uses a client/server model, which separates the front and back ends of the API and gives developers and implementers a lot of freedom in how they build and use it. REST is stateless, which means the API doesn’t store any data or information between requests. Caching is a feature of REST that stores responses for APIs that are slow or don’t need to respond quickly. REST APIs, which are usually called RESTful APIs, can also communicate directly or through middleware like API gateways and load balancers.

REST API Architecture Constraints

The REST architectural style describes six constraints:

  1. Uniform Interface: The uniform interface constraint defines the interface between clients and servers. In other terms, the First constraint of the REST API states that the Client and server have to communicate and agree to certain rules based on resources(they should communicate with the same resource like JSON, XML, HTML, and txt) and with proper encoding like UTF-8 extra. Another point is they should communicate with Self-descriptive Messages e.g. Using the same MIME types.
  2. Stateless: APIs in REST are stateless and the Client and server don’t worry about the state of the request or response.
  3. Cacheable: According to the World Wide Web, clients can cache responses. Responses should therefore, implicitly or explicitly, define themselves as cacheable. It’s up to the server when they want the cache to expire etc.
  4. Client-Server: Client and Server are two different entities, It means that servers and clients may also be replaced and developed independently, as long as the interface is not altered.
  5. Layered System: It means that between the client and the server, there can be as many-layered systems as needed.
  6. Code on Demand: Instead of client-side logic, the server can store the code or logic on its own and send it to the client when it’s needed.

If any API fulfills all the constraints then we can call it REST API.

SOAP

The simple object access protocol (SOAP) is a messaging standard defined by the World Wide Web Consortium and widely used to develop web application programming interfaces (APIs), typically with XML. SOAP supports a variety of Internet-wide communication protocols, including HTTP, SMTP, and TCP/IP. SOAP is also extensible and style-independent, allowing developers to write SOAP APIs in a variety of ways and add features and functionality with relative ease. The SOAP approach specifies how SOAP messages are processed, the features and modules included, the communication protocol(s) supported, and the SOAP message construction.

SOAP is a standard that is highly structured, tightly controlled, and precisely defined, in contrast to the flexibility of REST. SOAP messages, for instance, may contain up to four components, including an envelope, header, body, and fault, which are used for error handling.

RPC

The remote procedural call (RPC) protocol is an easy method for sending multiple parameters and receiving results. RPC APIs invoke executable actions or processes, whereas REST APIs primarily exchange data or resources, including documents. These APIs are referred to as JSON-RPC and XML-RPC, respectively. RPC can be programmed in either JSON or XML.

What to Test in API Testing?

  1. Validate the keys with the Min. and Max range of APIs (e.g maximum and minimum length)
  2. Have a test case to do XML, and JSON Schema validation.
  3. Keys verification. If we have JSON and XML APIs we should verify it’s that all the keys are coming.
  4. Verify how the API’s error codes are handled.

Let’s understand why API Testing is important…

Why you should perform API Testing?

  1. Many of the services that we use every day rely on hundreds of different interconnected APIs, if any one of them fails then the service will not work.
  2. Right now, the Internet uses millions of APIs and they should be tested thoroughly.
  3. Developers make mistakes and they create buggy APIs.
  4. Validation of APIs is very important which are going live to production.
architecture of an application & its testing part

The above image shows the architecture of an application & its testing part.

How to Test an API ( API Testing)?

Before that let us take a look at the example API which we can access freely.

https://simple-books-api.glitch.me/books

Here Keys are id, name, type, and available and they have corresponding values as number, string, or boolean. You can test API manually or use a tool. We always recommend using certain tools.

API Testing Tools

Here is a list of API testing tools. You can learn or use whichever tool you think is best for you. I recommend starting with Postman, which is a great API testing tool with lots of features like the command line, CI/CD, and API monitoring with test case support.

  1. Runscope.com
  2. Postman CI/CD
  3. Katalon using CI/CD
  4. SoapUI CI/CD
  5. Rest Assured CI/CD

API Testing using Postman

What is Postman?

First, let’s figure out what Postman is.

It is an API Testing tool that developers and testers use to test APIs. It has a lot of different features, such as global variables, mock requests, monitoring of the environment, and API monitoring.

Download Postman – https://www.postman.com

5 Major Features of Postman

  1. The Postman API: The Postman API lets you make requests to programmatically access, create, or update your Postman data, such as collections, environments, and monitors. You can also run monitors directly from the API.
  2. Code Snippets: Code snippets are small scripts that have already been written and it can be used in Postman to test API responses. Snippets use ChaiJS BDD syntax, and they make it easier to write tests so that you can make sure your software works the way you want it to.
  3. Workflow control: Consider you have a collection with four API requests. You wish to execute them sequentially, excluding the third request. You can accomplish this by utilizing the postman.setNextRequest() method, which allows you to specify the next request to execute.
  4. Postman Visualizer: The Postman Visualizer is a programmable tool that visually represents response bodies directly in the Postman UI.
  5. Collaboration: Postman provides many collaboration features for your upcoming hackathon project, including forking, version control, and comments. In a team workspace, you can fork a teammate’s collection to create a copy for your own use.

To learn more, Let’s see the next concept HTTP Fundamentals.

Leave a Reply