DEV Community

Cover image for Postman Monitors - The hidden gem
Saransh Dhingra
Saransh Dhingra

Posted on

Postman Monitors - The hidden gem

Postman is a great tool. I have been using it since it was just a browser extension and really loved the idea of testing my APIs before giving it to the frontend folks.

It has been a great help while I was learning about APIs and how to create them.

It has come a long way since then. Now, there are much more things like Mocks, Monitors etc (Actually they have been around a while but not the most popular).

In this post, I would specifically like to highlight how we can use Postman Monitors for some super cool things.

Before I begin, I feel obligated to point out that I am a Postman employee, but its not in my job description, nor have I been asked by anyone to write such a post. I do so, with my own free will(like Lucifer wanted us humans to have :P )

What are Postman Monitors?

So, monitors in the postman arsenal are in my opinion one of the most powerful weapons, one which we can choose to automate any kind of work(well most of them anyway).

  • Want to make sure your website isn't down every few minutes?
  • Want to run a series of tests on your APIs on regular intervals?
  • Want to be notified when a product is available on Amazon?
  • Want to set up a reminder when your favorite crypto reaches a benchmark(Go Litecoin).

It has got you covered!

Think of monitors as your serverless cron job alternatives, where you can customize what to do, when to do it, and what to do after it has been done!

I hope you're with me on this weird chain of thought!

Enough talk, get to action already!

In this post we'll check how to set up a monitor and do a very basic task of checking if your website is up or not at regular intervals and reporting via email if it is down.

Don't worry, we'll cover more awesome things in a future post.

First things first, you need to sign in by visiting https://www.postman.com

Step 1: Go to a workspace

Select a workspace

Well, all things in Postman reside in a workspace. So, the monitor we will be creating will reside in one of the workspaces you are a part of. Everyone, is a part of their own workspace(termed My Workspace) or you can create a new Workspace if you want to group your work separately.

Side note: We recently launched Public Workspaces and it is pretty cool, check it out in this blog post if you wanna know more.

Step 2: From the left sidebar, select collections and create one and add a request to it.

Create a collection

Add a request to your collection

Step 3: Add details about your webpage.

Add request details to your request

Here, I will be sending a GET request to https://saranshdhingra.dev

Yes, this is a shameless attempt to advertise my portfolio website. I feel terrible, so if you could just visit the website, leave awesome feedback and read the rest of the article, I'll be on my way :D

In order to test it you can quickly send the request to see if everything works.

You should get a 200 status code response if your webpage is up and configured properly.

Note that in order to run the request from the web and not the app, you may need to select the Desktop Agent to avoid CORS issues. If your website is configured to allow all Cross Origin Requests then you may not need this. You can select the agent in the bottom right section of the page.

Select the proper Postman Agent

Step 4: Add a testing mechanism

We have set up how to send a request to our webpage, but how do we know if everything works perfectly. We want to automate the whole process after all!

Enter the Tests tab.

Just below the bar where you entered your webpage address you may see a lot of tabs, one of them will be the Tests tab. When selected it looks like this:

Postman Tests tab

This is another tool in the Postman arsenal which I think is very powerful.

Think of this tab as a hook that runs after the request runs. So you can do all sorts of things with this, things like:

  • Getting the response body and parsing content.
  • Take some dynamic content and initiate another request based on that(we'll do this sometime later)
  • Check the status code of the response received(Bingo!)

So, in order to test if our website is working fine, every time we run our request, we'll be checking if the response code is equal to 200 or not.

This is how we do that:

pm.test("Check Status code of my website", function () {
    pm.response.to.have.status(200);
});
Enter fullscreen mode Exit fullscreen mode

So, put this in the Tests tab and Run the request. You should see that your test passed(check it in the Test Results tab in the response section).

Test Results in postman

Try changing the status code in the test temporarily and running the request again to see how it behaves when the test fails.

Save the request, and now we can move to the monitors part of the tutorial

Step 5: Create a monitor for your collection

Create a monitor

From the left sidebar, select Monitors and Create a Monitor.

  • Enter a meaningful name for your monitor.
  • Select the collection that we created earlier.
  • For now, you can keep the Version as CURRENT, and Environment as No Environment, we'll use them in future tutorials.
  • Select the desired frequency. For a normal, portfolio-like website an hourly frequency should suffice.

Please note that if your monitoring calls have a quota, you get 1000 monitoring calls free every month. You can check your current usage by going into the Resource Usage page.

Monitoring usage

The options should look something like this:

Set monitoring options

Additional Options:
You can set some additional options for more granular control over your requests.

For example, you can send the requests from multiple regions that ensures your website behaves similarly in different regions.

A very important option is to have an email sent to you whenever a Test fails on your monitor run.

So, if your website returns with a non 200 status code, you can get an email for the same.

We'll talk about cooler delivery methods in a future tutorial, but for now, let's select that.

Additional options while creating a monitor

Step 6: Run your monitor

You can either wait for your monitors to run at their designated time or Run them manually for testing. After running them, you see the records of individual instances when you had requested/scheduled the monitor to run.

By clicking on a specific bar, you can see more details about the requests and the test results.

Postman monitor Run results

Conclusion

So, we created a collection, set up a test that checks for a deciding criteria to know whether the website is up or not, and then automated the whole process to run at scheduled intervals.

I don't know about you, but I was very thrilled the first time I did this. I could imagine so many possibilities to achieve things that I needed to automate. Things that I knew how to achieve in code, but this was a whole other domain, no need to manage crons, no need to manage servers, and all from a tool that I use to test my APIs already.

Right now this is just a basic run through of a part of the product, but we'll get into more details, and we'll try to achieve something cool every time.

Stick with me, and you'll find Zen!
Actually no, I'm finding that myself, send me a link when you find it :P

Top comments (1)

Collapse
 
hayks profile image
Hayk Sardaryan

Great article !