REST API Testing Tutorial – Sample Manual Test Cases

What is REST API Testing?

REST API Testing is open-source web automation testing technique that is used for testing RESTful APIs for web applications. The purpose of rest api testing is to record the response of rest api by sending various HTTP/S requests to check if rest api is working fine or not. Rest api testing is done by GET, POST, PUT and DELETE methods.

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.

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

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.

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

How to install Advance Rest Client

  • 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”

http://ip.jsontest.com/

Step 1) Open Advanced REST client

Launch the app Advanced REST client (ARC), once it is installed successfully.

Open Advanced REST client

Step 2) Enter the URL of API to test

Enter the sample REST API URL for testing in the URL textbox.

URL of API to test

Step 3) Select the HTTP method

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

HTTP Method

Step 4) Provide Headers set

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

Headers Set

Step 5) Confirm the Headers set

Next Click on USE THIS SET.

Headers Set

Step 6) Provide required Body content

  1. Now switch to Body Tab.
  2. Set the required Body content type and Editor view e.g. Body content type : application/json
  3. Editor view : Raw input.
  4. 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.
{"property" : ["Sites"], "report_type" : ["ALL"]}

Steps for Testing REST API

Step 7) Submit the details to start the test

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

Steps for Testing REST API

Here are the response details:

Steps for Testing REST API

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.

Validating the Results

REST API Test Tool

Challenges for API Testing

The interesting problems for testers while REST services testing 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 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
  4. Sequencing API calls as per the order in which the function 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 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.