Using Api Testing with Postman

Emre Dogangun
3 min readJun 20, 2022

API (Application Programming Interface) What is it?

Postman is a platform that allows you to create our tests faster when developing Web services. The parameters determined by the requests are sent and then the response is returned.

Commonly Used HTTP Request Methods

1-) GET: With this method, you can get data from the server.
2-)POST: With this method, you can send/print data to the server.
3-)PUT: With this method, you can update the data on the server.
4-)DELETE: With this method, you can delete the data on the server.

We can start testing the paths at the https://petstore.swagger.io/ URL.

The first step is to create a collection, when we click the new button in the workspace and select collection, we will create it.

After creating, we will need to give it a name.
To create a new request, it is sufficient to select the add request by clicking the three dots next to our collection.

Let’s test the method https://petstore.swagger.io/v2/pet, the http request will be POST and it will be necessary to write the request as a json type body.

When we send the Postman POST request, the response will be returned.

We can add headers in this way. Generally, token additions are made in this part.

This is how we can run my tests to check the returned response jsons. You can use the Snippets on the right:

pm.collectionVariables.set(“id”,JSON.stringify(res.id));

we can assign collectionVariables variable with these codes.

We can add value ourselves. Base urls are usually written here.

We can write methods with javascript in the pre-request script part. In these methods, we can save the returned values to collection variables and use them in our requests.

We can assign a url value in the params section. When we assign a value of 1 to petId, the url will now take the form pet/1.

You can export by clicking the three dots in the Collection or import from the top.
You can also run your Postman cases using new man.

npm install –g newman

npm install -g newman-reporter-htmlextra

Run these commands in order. Then run the following command to run the cases.

newman run /Users/{{username}}/Documents/postman-export.json -r htmlextra

This way it will report.
Thank you…

--

--