SAP

Web

Must Learn!

Big Data

Testing

Rest stands for Representational State Transfer. It is an architectural style and an approach for communication used in the development of Web Services. REST has become a logical choice for building APIs. It enables users to connect and interact with cloud services efficiently.

In this tutorial, we will learn how to test REST API manually.

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

  • Testing Tool to drive the API
  • Writing down your own code to test the API

In this tutorial, you will learn-

What is API

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

http://<server name>/v1/export/Publisher/Standard_Publisher_Report?format=csv

There are mainly 4 methods involve in API Testing like 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 send data to the server, for example, customer information, file upload, etc. using HTML forms.
  • PUT- Replaces all current representations of the target resource with the uploaded content.
  • DELETE- Removes all current representations of the target resource given by a URI.

How to Test REST API

Rest API 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 REST 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 "http://ip.jsontest.com/."

Step 1): Launch the extension once it is installed successfully.

Testing REST API Manually

Step 2): Enter the URL of the API in the URL textbox

Testing REST API Manually

Step 3): Select the radio button for the type of HTTP method to hit- e.g. POST

Testing REST API Manually

Step 4) : Provide Headers (if required), in the Headers textbox. Sometimes we need to give headers like

Content-Type: application/json

X-User-Type: standard

Testing REST API Manually

Step 5): Under Payload, pass the request body of the API 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.

Testing REST API Manually

Step 6): Set the required content type e.g. application/json

Step 7): Hit the send button. After clicking on "send" button, you will see response something like this.

Testing REST API Manually

Here, we have used "POST" method, in the same way, we can use remaining methods like GET, PUT, DELETE, etc.

Validating the results

Mainly, for 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.

Testing REST API Manually

REST API Test Tool

Challenges for API Testing

The interesting problems for testers are:

  1. 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
  2. Creating interesting parameter value combinations for calls with two or more parameters
  3. Identifying the content under which the API calls has to be made. Which might include setting external environment conditions ( peripheral devices, files, etc.) as well as internally stored data that affects the API
  4. Sequencing API calls as per the order in which the functionality will be executed
  5. 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 API Testing like Get, POST, Delete, and PUT.
  • We need to check response code, response message and response body in API Testing.

 

YOU MIGHT LIKE:
Software Testing

Learn SOA Testing

What is SOA Testing? SOA Testing is a Testing of Service Oriented Architecture (SOA) which is an...