Api Testing with Hoppscotch
Tags: hoppscotch, restapitesting, opensource, pwa
Published: 2022-01-25 04:31:43

Hoppscotch is light-weight, web based API development suite. It was built from ground up with ease of use and accessibility in mind providing all the functionality needed for API developers with minimalist, unobtrusive UI. It is free-to-use and as an added perk completely Open Source!
**Creating collections**
It is always a good practice to create a collection and add requests under the collection. To create a collection first click on Collections button and click on New button.
![Creating collection](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yhqepby7ajjoj2smlwi9.png)
Give a suitable name for the collection and click Save.
![Collection name](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z584xctj92yhv4r1boq3.png)
The new collection created will be displayed under My Collections tab.
![Collection created](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/llb2pcusmkfjhk22txz3.png)
**Adding first request under the Collection**
In this blog I will be using REST apis provided by https://reqres.in/. I have used SINGLE USER api that supports http get method.
![Reqres](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jv53ferer95swiafamsg.png)
Copy the api end point and paste in hoppscotch. Before hitting the api save the api in the earlier created collection. For that click on the arrow button and click on Save as button.
![Adding request in hoppscotch](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rxadg9encpcy1b0hyn0o.png)
Give a Request name, choose the desired collection in which you want to save the request and click Save button.
![Request name](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yakw64wo7x2wo6tedwfr.png)
The new request will be displayed under the newly created collection.
![Request created](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fhd60lki4c1ikgrfjqfa.png)
Now click on the Send button and view the response from the api.
![Response of api](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bnk5dprhfgcf711wzgtf.png)
**Creating environment and adding variables under it**
Click on Environments button and click New button.
![Adding environment](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zigpzo1jwi4fq5pize2m.png)
Add environment name and click Save
![Add environment name](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2xnw52gajjwyhv4es6nr.png)
In order to add a variable click on the newly created environment and click on Add new button.
![Add variable](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s1k9x68x3o321pkwodib.png)
Add variable name and variable value. After that click on Save button.
![Add variable for environment](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sgl5q898yid141pmxem6.png)
**Accessing environment variable**
To access the environment variable use << variable_name >> object in request section and also make sure that the correct environment is selected from the top right corner for the request.
![Accessing env variable](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o2dsd7vfhy8baoi2gd3b.png)
Now click Send and same result will be displayed as earlier.
![Sending request](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gh5gkpxbogvcac3v2cqu.png)
**Adding Tests(assertions) for the request**
These are some of the tests performed on the response. More tests can be found from this link https://docs.hoppscotch.io/features/tests
 ![Adding tests](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7q9w1zd05ujrb2ja2ylm.png)
Results of the tests will be displayed in the Test Results tab
![Tests results](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4vf2au9xzozwhi4p5kj9.png)
If you need any clarifications regarding this post, please comment below the comment section.