Basics of Web API testing

SECTIONS

IntroductionWhat is API testing?Why API testing is important?Understanding URL and URIDifference between URL and URI
Introduction
In the ever- growing world of software development, the success of a software application depends on successful testing. Most of the modern applications have a layered design which must be tested to ensure these layers meet expectations. The main functions of the application are present in the middle layer (API) which is an integral component that must be tested.
One popular software testing type is API, which stands for Application Programming Interface. In the present era of software development, API is pivotal in ensuring all the components work in tandem. A thorough API testing therefore becomes an integral part of the entire process of testing.This article aims to discuss all about API testing. If you want to know more about API testing, and don’t know where to start, this article is for you.
Let’s get started.

What is API testing?
As mentioned earlier, API is an abbreviation for Application Programming Interface. In the process of software development, API comes between the user interface and the database layer. This is a critical component as it provides a smooth connection for the exchange of data between two different software.

The process of API testing primarily aims to ensure proper functionality and performance of this interface. Unlike in other testing processes, API testing uses software for the purpose of sending calls to API and to tap the output and response of the system.The focus of API testing is primarily on the Application User Interface, which is also called the Business layer unlike in other forms of testing where the focus lies on the user interface and data base testing.

The below mentioned diagram depicts where API testing takes place.

The User Interface layer is the one which communicates with the end users, however, apart from this, these layers are designed to effectively communicate with each other. It is the API s which make this communication a smooth process.

API’s act like connectors between the layers of the application. Most applications have three layers namely a Presentation layer, a User Interface layer and Database layer. It is the API layer which contains all the protocols for interaction with other functionalities and services of the application.Most importantly, API layer being in connect with the data and presentation layers respectively, proves to be extremely advantageous for testing purposes.

Although API has multifold aspects, the process in general involves sending requests to one or more API endpoints followed by validation of the response primarily to ensure performance standards, functionality checks and other security related checks. As mentioned earlier, the focus of API testing is the business layer.

Why API testing is important?
API s play an indispensable role in the world of modern software development. One of the most important benefits offered by APIs is that it enables organizations to develop applications which have reliance on other applications but do not need a constant upgradation even when changes are made to the dependent software.

It is the API which must be stable irrespective of any changes made to the implementation. Therefore, the layer which is responsible for storing protocols of operations, formats of data remains constant even when there are changes to implementation.

With the latest progression to cloud computing, the importance of API s has grown manifolds. With a constant surge in the number of cloud applications and platforms which are interconnected, API testing is a priority. Most of these applications running on cloud are dependent on many other API s which are integrated, failure of any one of them means that the service will not work.

Apart from this, there are numerous other benefits of API, which have been mentioned below-

  • No dependency on a particular language for testing- The exchange of data happens through structured XML and JSON formats which ensure the process of verification is highly quick and stable. Built-in libraries enable comparison of data with the help of these formats.
  • No dependency on GUI- API testing is not dependent on GUI testing which means it can be conducted before the GUI testing is conducted. This leads to improved and efficient testing of the core functionalities of the application and even the smallest of errors are captured.
  • Better test coverage- Many of the API s allows creation of automated tests (like functional and non-functional testing) which have a high range of coverage.
  • Quick Releases- It has been proven that with the execution of API testing is far quicker than UI testing thereby allowing the developers to provide quick release of the product. This also makes API testing a cost- effective solution.
  • Combat vulnerability- The conditions required for API testing are known to prevent any malicious attack on the application as the API tests ensure the software is stretched to the connective limits.
Understanding URL and URI
The world of internet, also called as the web world is a sea of information. This information is useful only when is available on time. The terms ‘URL and URI’ are not alien in the world of internet. While these two terms have been used interchangeably, there indeed are differences between the two. Let’s understand the main points of difference between the two.URI stands for Uniform Resource Identifier. It is a string which helps to identify a particular resource on the internet. This resource can be either physical or logical.  It uses name or location or sometimes both to identify the resource. For the purpose of standardization, URI has a syntax which is as follows-
scheme:[//authority]path[?query][#fragment]

Let’s understand each of these items separately.
First, we have ‘Scheme’ which has a series of symbols formed by combination of letters, numbers, plus sign(+) or even hyphen(-) along with a colon (:). Some of the commonly used schemes are http, ftp etc. It is important for scheme to have registration with IANA.
Next, we have ‘authority’. It is a purely optional and has 2 slashes (//) before it. Authority has 3 sub-items.
  • User info: This item may have a username, but the password is optional and is separated by a colon and has @ sign following it.
  • Host: This may have one of the following- an IP address or a registered name. It is the IP address which has [] brackets enclosing it.
  • Port: This is an optional item.
The next item is Path which has a series of path groups or segments which are separated using a slash (/). Path is always specified by URI but the path which is specified may either be empty or may have zero length.
Query and Fragment are both optional items. While query has a question mark (?) before it, fragment has a hash symbol (#) before it.
URL (Uniform Resource Locator) and URN (Uniform Resource Number) are both a part of the bigger URI group.
URL s are mostly used in connection with web pages (HTTPS), however, they can also be used for accessing database with the help of JDBC, email, FTP (file transfer) etc. If you are wondering what URL is, here is a simple definition.
URL can be defined as a global address for resources along with the rules to retrieve these resources. Like URI, URL also has a similar syntax-
scheme:[//authority]path[?query][#fragment]

Let’s now look at each of these individual items as well.
The first item in the syntax is scheme. It mainly refers to the rules or protocols which are required by a browser while sending a request for a resource. Most websites usually use HTTP or HTTPS protocols.
The next item is ‘authority’ which comprises of two sub-items namely the name of the domain and port. These two sub items are separated by a colon. While the domain name can be any name under which the resource is registered, port, on the other hand is like a toll gate to gain access to the resource available on the web server.

Path includes the entire route to the resource available on the webserver.
Query- The series which has the pair of name and value. In case of a URL, query follows the path to yield the required information.
Fragment- Like in URI, fragment is an optional item in URL as well and contains hash (#) symbol before it. The Fragment identifier directs to a secondary resource.

Difference between URL and URI
If you are thinking that URI and URL are quite similar, then hold on! Below are some of the main points of difference between the two.

URL
URI
Uniform Resource Locator
Uniform Resource Locator
Sub item of URI, used to identify the location of the resource
Has URL and URN as sub items. URN is used for identifying the  resource by the name.
URL s are always URI because they can only identify location of  the resource.
Not all URI s are URLs. Some URI can identify name or location.
In BDD, the beginning point is a scenario.
In TDD, the beginning point is a test case.
It is a team process.
TDD is a development practice.
Commonly used for finding web pages.
Most of the usage is for XML and tag library files.
Scheme is mostly protocol for example HTTP, HTTPS etc.
Scheme is not limited to just protocol but may also include designation,  specification or other details.