GAZAR

Principal Engineer | Mentor

Exploring Postman: Tips and Tricks for Effortless API Testing and Development

Exploring Postman: Tips and Tricks for Effortless API Testing and Development

I wanted to explore Postman features, and here's a post on all the little things you can do with Postman. There are tons of features, and they are still developing new ones, so let's dig in.

First things first, use their tabs to create a request for your APIs and then click Send. It's easy! You can create Collections, which come in handy, and I like the syncing system between browsers and so on. I can define params, headers, payloads, and all the details for my request as well.

Then I went ahead and created an environment, put my domain there as a variable, and they have global variables for more secret variables, so I put my token there.

Screenshot 2023-12-31 at 1.28.21 pm.png

Which is nice; you can decide to put your token into your environment or global variables. They want it to be secure, so globals are meant for that.

Then they have a 'Visualize' section. You can prettify your requests, visualize them in a bar chart or a table.

Screenshot 2023-12-31 at 1.58.50 pm.png

Another fun part is to use the 'Test' tab and write tests for your requests. It will run every time you click 'Send.' So, a code like this will test the status:

pm.test("Status code is 200", function () {
    pm.response.to.have.status(200);
});

and you can imagine like jest or any other libraries, you can write many more tests and run them each time.

then you see

pm.visualizer.set(template, constructVisualizerPayload());

This is placed here after clicking on the 'Visualize' tab.

Take a look at the 'Settings' tabs and many other little features, like validating SSL, which is an option there. You probably want to test that for your production environments.

Are you working with cookies? And you want to manage the cookies for a specific domain? There is a 'Cookies' section, and you can edit your cookies for any domain.

Screenshot 2023-12-31 at 2.02.35 pm.png

Once you think you have what you need, there is a Postbot. Click on adding tests for your response, and like ChatGPT, you get this code:

pm.test("Response status code is 200", function () {
    pm.response.to.have.status(200);
});

pm.test("Response is an object with a status property", function () {
    pm.expect(pm.response.json()).to.be.an('object').that.has.property('status');
});

pm.test("Response has an array of events", function () {
    pm.expect(pm.response.json()).to.have.property('events').that.is.an('array');
});

The other thing is documentation. Who likes to write if AI does it for you? The beauty of this is, I haven't done anything, and it just works.

Screenshot 2023-12-31 at 2.27.56 pm.png

The other interesting thing is to create monitors and run your tests on a schedule, which is a perfect way of automation. Like 1000 requests for 0.75 USD, and you can go from there.

Screenshot 2023-12-31 at 3.44.02 pm.png

This is so handy if you can make the argument for your case that it's worth running it. The other one is Mock Servers. You want a sample endpoint with a specific response? You can just add a mock server.

Screenshot 2023-12-31 at 3.52.19 pm.png

Or if you want, you can save the response examples for future use cases and have a faster view.

Screenshot 2023-12-31 at 3.50.28 pm.png

At the end, you can run all tests within your collection, which is quite handy, especially when you are developing new APIs to make sure you haven't broken the previous ones.