An API or Application Programming Interface is a set of programming instructions for accessing a web-based software application. In other words, a set of commands used by an individual program to communicate with one another directly and use each other’s functions to get information. For example, a Google website can have API for various functions like search, translations, calendars, etc. In general API’s are like below, they have server name, paths.., etc

Types of API Methods

There are mainly 4 types of API Testing methods: GET, POST, Delete, and PUT.

GET– The GET method is used to extract information from the given server using a given URI. While using GET request, it should only extract data and should have no other effect on the data.

POST– A POST request is used to create a new entity. It can also be used to send data to the server, for example, customer information, file upload, etc. using HTML forms.

PUT– Create a new entity or update an existing one.

DELETE– Removes all current representations of the target resource given by a URI.

In this REST API testing tutorial, you will learn-

What is REST API? How to Test REST API Steps for Testing REST API Validating the results REST API Test Tool Challenges for API Testing

How to Test REST API

API testing requires an application to interact with sample API for testing. To test an API, you require two things,

Testing Tool/Framework to drive the API Writing down your own code to test the sample REST API

Rest API test cases can be tested with tools like:

Advanced Rest Client Postman-Rest Client Curl in Linux

Here we will be using Advanced Rest Client, below are the steps to get Advance Rest Client,

How to get Advanced Rest Client?

Go to Google Chrome’s Web Store Search for “Advanced Rest Client” or directly go here and Install the extension

Select the “Advanced Rest Client” icon under chrome’s app section – chrome://apps/

Once the installation is done, follow the below test for Testing RESTful API

Steps for Testing REST API

Here we are using rest client extension in chrome browser. To understand in a clear way, we are using dummy API for testing” Step 1) Open Advanced REST client Launch the app Advanced REST client (ARC), once it is installed successfully.

Step 2) Enter the URL of API to test Enter the sample REST API URL for testing in the URL textbox.

Step 3) Select the HTTP method Select the method for the type of HTTP methods in API testing to hit- e.g. POST

Provide Headers Set, in the Headers textbox. Click on Insert header set.

Step 5) Confirm the Headers set Next Click on USE THIS SET.

Step 6) Provide required Body content

Now switch to Body Tab. Set the required Body content type and Editor view e.g. Body content type : application/json Editor view : Raw input. Under Payload, pass the request body of the demo API for testing in the form of key-value pairs e.g. {{“key1″:”value1″,”key2″:”value2”}. If it is post API, then we need to pass body or parameters. We will pass under given payload.

Step 7) Submit the details to start the test

Hit the send button. You can click on DETAILS button to see the Response headers.

Here are the response details:

Validating the results

Mainly, for Web API Testing, we need to check response code, a response message, and response body. Below are the various response code, one might encounter while API Testing.

REST API Test Tool

JMeter

Challenges for API Testing

The interesting problems for testers while REST services testing are:

To make sure that the test harness varies the parameters of the API calls in such a way that it verifies the functionality as well as expose the failures. It includes exploring boundary condition and assigning common parameters Creating interesting parameter value combinations for calls with two or more parameters Identifying the content under which the API calls have to be made. Which might include setting external environment conditions ( peripheral devices, files, etc.) as well as internally stored data that affects the API Sequencing API calls as per the order in which the function will be executed To make the API produce useful results from successive calls.

Summary:

An API or Application Programming Interface is a set of programming instructions for accessing a web-based software application. There are mainly 4 methods involve in REST API automation testing like GET, POST, Delete, and PUT. We need to check response code, response message and response body in API Testing test cases.