Prerequisites

Familiarity with HTTP Request types and basics of RESTful Web Services and APIs is recommended.


Please check the following article for more details on Header and Body comparison modes in Web Services Testing - Comparison Modes in Web Services Testing



Resources

We will be using the following API Endpoints for our examples:

https://jsonplaceholder.typicode.com/posts
https://jsonplaceholder.typicode.com/posts/1
https://jsonplaceholder.typicode.com/posts?userId=1


These are provided by JSONPlaceholder - A free API Service available online for REST API Testing purposes.


Let us see how each of the Request Types is tested in Testsigma.



Steps required for creating a RESTful Web Service Test Step


If you are new to Web Service Testing in Testsigma, please check the following article for more details on creating Test Steps for REST API Testing - How to add Test Steps for Web Service/API Testing?


Once you are in the Create Test Step wizard,

1. Enter a relevant Title for the Test Step

2. Enter the URL endpoint for the API

3. Select the HTTP request method(GET,POST,PUT,DELETE, or HEAD)

4. Enter the Payload values and Request Header in JSON Object format

5. Select the Tests you want to perform - Comparing any of Status Code, Header, Body of Response or all of it. According to the Tests you selected, new fields will be introduced to enter the Expected value in JSON Object format

6. Enter the Expected Response values in respective fields and select the Comparison types such as Strict, Lenient e.t.c.


Let us consider the scenario of sending a GET request.




1. GET - Verify the status code for a GET request


We will be using Testsigma to verify the Status Code of the response for a GET request sent to the following URL.

  • Enter the Endpoint URL - https://jsonplaceholder.typicode.com/posts
  • Select the HTTP Request Method Type - GET
  • Enter the Request Header if needed
  • Select the Test Type/Types - Status Code
  • Enter the Expected Status Code - 200



Finally, Click on the Create button to create the Test Step.


The same procedure can be followed for other Request Types with minor variations.




2. POST - Verify the Body Content for a POST request


We will be using Testsigma to verify the Status Code and Body Content for a POST request sent to the following URL with some Payload.

  • Enter the endpoint URL - https://jsonplaceholder.typicode.com/posts
  • Select the HTTP Request Method Type - POST
  • Enter the Payload data and Request Header as given below.
  • Select the Test Type - Body Content
  • Select the Comparison Type - Lenient
  • Enter the expected Body content from the Response.


Header:

{
    "Content-type": "application/json; charset=UTF-8"
}


Payload:

{
    "title": "foo",
    "body": "bar",
    "userId": 1
}


Expected Response Body Content:

{
    "id": 1,
    "title": "foo",
    "body": "bar",
    "userId": 1
}





3. PUT - Verify the Status Code and Body Content for a PUT request


We will be using Testsigma to verify the Status Code and Body Content for a PUT request sent to the following URL with some Payload.

  • Enter the endpoint URL - https://jsonplaceholder.typicode.com/posts/1
  • Select the HTTP Request Method Type - PUT
  • Enter the Payload data and Request Header value as given below.
  • Select the Test Type - Status Code & Body Content
  • Enter the Expected Status Code for the Response - 200
  • Select the Comparison Type for Body Content - Lenient
  • Enter the expected Body Content for the Response as given below.

Header:

{
    "Content-type": "application/json; charset=UTF-8"
}


Payload:

{
    "id": 1,
    "title": "foo",
    "body": "bar",
    "userId": 1
}


Expected Response Body Content:

{
    "id": 1,
    "title": "foo",
    "body": "bar",
    "userId": 1
}





4. DELETE - Verify the status code for a DELETE request


We will be using Testsigma to verify the Status Code of the response for a DELETE request sent to the following URL.




5. HEAD - Verify the status code for a HEAD request


We will be using Testsigma to verify the Status Code of the response for a HEAD request sent to the following URL.