Configuring Multi Cluster Setup in Postman

Written by arvindkgs | Published 2021/01/13
Tech Story Tags: postman | distributed-infrastructure | testing | rest-api | backend | webhook | api | programming

TLDR Using pre-request script to store the access tokens, refresh token as a value object in a map with key being the cluster URL. This can be avoided by using environment variables. Using environment variables, you can switch to different clusters easily by switching the environment. The code is set via the environment variables. It is now possible to use the environment to switch between clusters in different environments. The configuration is set by the same environment that is used for a single cluster setup in the US and EU data center.via the TL;DR App

If you are testing REST APIs application with Oauth on Postman, generally you do the following,
  • Send a OAUTH request to an /auth endpoint and copying the access token, and setting header as ‘Bearer <access-token>’ in actual request.
  • This copy-paste be avoided if you set following pre-request script in pre-request tab
    This will execute the Oauth request before executing the actual REST
    API, and store in a global variable. So consecutive calls will utilize
    the stored global variable.
Above works great for a single cluster setup.
However for a multi cluster setup, where you have one cluster in say EU data center, another in US, then you would need to duplicate this setup. I have seen developers Postman flooded with hundreds of similar requests, with only change being the URL, like below with over 184 requests
This can be avoided by using environment variables.
I have modified the pre-request script to store the access tokens, refresh token as a value object in a map with key being the cluster url. This url is set via the environment variables.
So now I can switch to different clusters easily by switching the environment.

Written by arvindkgs | Passionate software developer, Linux enthusiast, clean code crusader, DIY advocate, Tech Evangelist
Published by HackerNoon on 2021/01/13