We will be demonstrating how RESTful APIs or Web Services can be tested using Testsigma in this article. In this demo, we are going to use JSONPlaceholder which is a free online REST service that you can use whenever you need some fake data.


API resources and routes

Resources

API Entry point - https://jsonplaceholder.typicode.com/


These are the resources or fake data available for inspection via the API. The left column specifies the url for the request and right column specifies the number of JSON object items returned in the response.

/posts
100 items
/comments
500 items
/albums
100 items
/photos
5000 items
/todos
200 items
/users
10 items


We can append any of the above resource names to the API entry point to form a valid GET request.


Routes

A few of the available routes are given below:

https://jsonplaceholder.typicode.com/posts                            - will return a response containing 100 posts

https://jsonplaceholder.typicode.com/posts?userId=1            - will return a response containing the posts for userid=1

https://jsonplaceholder.typicode.com/posts/1                         - will return a response containing the post with id=1

https://jsonplaceholder.typicode.com/posts/1/comments        - will return a response containing the comments for post with id=1

https://jsonplaceholder.typicode.com/comments                    - will return a response containing 500 comment items

https://jsonplaceholder.typicode.com/comments?postId=1    - will return a response containing the comments for post with id=1

https://jsonplaceholder.typicode.com/users                            - will return a response containing 10 users

https://jsonplaceholder.typicode.com/users/1                         - will return a response containing the user details for id=1


All of the most common HTTP verbs such as GET, POST, PUT, HEAD, and DELETE are supported.

Please check this article for more details on HTTP Request Types - Usage of various HTTP requests for REST API Testing in Testsigma

Also please check this article if you are new to Web Service Testing in Testsigma - How to add Test Steps for Web Service/API Testing?


Demo Test

Now, let us discuss how we can test the above API using Testsigma.

We will perform a total of 8 tests as given below:

1. Test the Expected Response Status Code for a simple GET request

2. Test the Expected Response Header for a GET request

3. Test the Expected Response Body for a GET request

4. Test the full Expected Response(Status Code, Header, and Body) for a GET request

5. Create a user using POST request and test the Expected Status Code, Header, and Body

6. Create a user using PUT request and test the Expected Status Code, Header, and Body

7. Test the Expected Response Header for a HEAD request

8. Delete a user using DELETE request and test the Expected Response


1. Test the Expected Response Status Code for a GET request

This Test checks for the Expected Status Code of the Response for a simple GET request( no request header provided). The following entries are to be made in Testsigma:


URL: https://jsonplaceholder.typicode.com/users

HTTP Method: GET

Test: Status Code

Expected Status Code: 200




2. Test the Expected Response Header for a GET request

This Test checks for the Expected Header of the Response for a simple GET request( no request header provided). The following entries are to be made in Testsigma:


URL: https://jsonplaceholder.typicode.com/users

HTTP Method: GET

Test: Header Test

Expected Header Content: {"content-type":"application/json; charset=utf-8"}

Header Comparison Type: Lenient


Please check this article for more details on comparison Types - Comparison Modes in Web Services Testing



3. Test the Expected Response Body for a GET request

This Test checks for the Expected Body Content of the Response for a simple GET request( no request header provided). The following entries are to be made in Testsigma:


URL: https://jsonplaceholder.typicode.com/users/1

HTTP Method: GET

Test: Body Test

Expected Body Content: {"id": 1,"name": "Leanne Graham","username": "Bret","email": "Sincere@april.biz"}

Body Comparison Type: Lenient



4. Test the full Expected Response(Status Code, Header, and Body) for a GET request

This Test checks for the complete Response(Status Code, Header and Body) for a simple GET request( no request header provided). The following entries are to be made in Testsigma:


URL: https://jsonplaceholder.typicode.com/users/1

HTTP Method: GET

Test: All(Status Code, Header Test, and Body Test)

Expected Status Code: 200

Expected Header: {"content-type":"application/json; charset=utf-8"}

Comparison Type: Lenient

Expected Body: {"id": 1,"name": "Leanne Graham","username": "Bret","email": "Sincere@april.biz"}

Comparison Type: Lenient



5. Create a post using POST request and test the Expected Status Code, Header, and Body

This Test creates a post using POST request and checks for the Header, Body and Status Code of Expected Response with no request header. The following entries are to be made in Testsigma:


URL: https://jsonplaceholder.typicode.com/posts

HTTP Method: POST

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

Test: All(Status Code, Header Test, and Body Test)

Expected Status Code: 201

Expected Header: {"content-type":"application/json; charset=utf-8"}

Comparison Type: Lenient

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

Comparison Type: Lenient



6. Update a post using PUT request and test the Expected Status Code, Header, and Body

This Test updates a post using PUT request and checks for the Header, Body and Status Code of Expected Response with no request header. The following entries are to be made in Testsigma:


URL: https://jsonplaceholder.typicode.com/posts

HTTP Method: PUT

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

Test: All(Status Code, Header Test, and Body Test)

Expected Status Code: 200(updated), 201(created) or 204(no content)

Expected Header: {"content-type":"application/json; charset=utf-8"}

Comparison Type: Lenient

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

Comparison Type: Lenient




7. Test the Expected Response Header for a HEAD request

This Test checks for the Header of the Expected Response for a simple HEAD request with no request header. The following entries are to be made in Testsigma:


URL: https://jsonplaceholder.typicode.com/posts/1

HTTP Method: HEAD

Test: Header Test

Expected Header: {"content-type":"application/json; charset=utf-8"}

Comparison Type: Lenient




8. Delete a user using DELETE request and test the Expected Response

This Test deletes a user and checks the Expected Header Response for a simple DELETE request with no request header. The following entries are to be made in Testsigma:


URL: https://jsonplaceholder.typicode.com/users/1

HTTP Method: DELETE

Test: All(Status Code, Header Test, and Body Test)

Expected Status Code: 200(done with response), 202(might succeed) or 204(done)

Expected Header: {"content-type":"application/json; charset=utf-8"}

Comparison Type: Lenient



Happy Automation Testing!