The increasing proliferation of APIs in combination with shifting IT environments makes strong collaboration tools essential for many developer and IT teams. Postman, a collaboration platform for API development, is a top choice for many organizations. A free application, Postman is useful for exploring APIs, building workflows, and sharing use case samples with anyone, such as a teammate. It’s especially handy when building dynamic variables to use across multiple environments.
With Postman, teams are able to collaborate through the use of collections and environments. It also has the ability to use a Collection Runner, which allows automated testing to iteratively run. The Postman console checks what data has been retrieved to make test debugging easy.
Before writing a bunch of code, I will usually mock up workflows using Postman to map out the steps and identify data types like parameters and variables. In this post, I will walk through a few use cases and tips to guide you along your automation journey using Postman.
Being able to build requests and workflows using a GUI is great, but collections are where Postman really stands out. Collections are simply groups of requests organized into folders to help organize your workflows and test suites. Each collection can contain subfolders and a number of requests. Collaboration is made easy with the ability to export and share collections.
At Rubrik, we publish new collections containing all of our REST endpoints with each product release. You can find and download Rubrik Postman Collections on GitHub.
Generate Code Snippets
One of my favorite features is the ability to instantly generate code snippets in the language of choice. I can then copy and paste that snippet into another app.
To do this, simply select an API call, click Code on the right and choose a language.
You then can customize the way the code snippets are generated, though available settings vary based on the selected language. You can configure a number options, such as specific linting requirements or personal preferences.
This functionality allows you to quickly supplement the construction of various scripts and automated functions across your infrastructure. If you don’t see the language or setting you want, Postman accepts contributions to its open source project.
Often when working with APIs, I find myself needing to have different setups. For example, I may be working across my local machine, a production API, and a test server. Environments in Postman allow me to customize API requests using variables. This means that once the values are input, I can quickly and easily switch between different setups without needing to rebuild my API requests. Environments can also be exported as JSON files to collaborate with teammates. Some common use cases include:
- API tokens, shared secrets, or user credentials; it’s usually a good security measure to keep this information out of your codebase.
- URLs referring to your Rubrik clusters or other platforms; for example, you could specify test-rubrik.example.com in development versus rubrik.example.com in production consistently across your API requests.
- Any other configuration specifications, such as which workloads and points in time that you are working with.
Environments in Postman are configured as simple key-value pairs, where both the key and value are defined as strings.
One of the most obvious reasons to use Environments is to pass authentication information in the request headers. Otherwise, you would be required to enter your credentials with each API request. To avoid this, you can edit the Collection and input variables for your username and password (or API key).
Next, define the variables as global (used across the entire workspace) or within a specific environment.
You can find and download an example environment for interacting with Rubrik APIs on GitHub.
Test Workflows with a Collection Runner
Once you have grouped together a series of API requests, you can use a collection runner to run the requests as a set against a corresponding environment. This is helpful when you want to test a workflow. Simply run a collection, and it will send all requests in the collection one after another.
You are able to specify which environment, how many run iterations, logging, and more to customize the workflow automation.
After the collection runner completes, it will show a summary of any tests that were included within each request and the details of whether the tests passed or failed during the run. For advanced use cases, you can even integrate this functionality with your favorite CI tool.
Something I’ve run into a few times is the “could not get any response” error. This could happen for a number of reasons, such as proxy configuration, incorrects request URLs, using https:// instead of http:// or vice versa, or short timeouts. However, most commonly this is due to the use of self-signed SSL certificates, often used in test environments.
If you are using self-signed certificates, then you can turn off SSL certificate verification. You can find this toggle under Settings.
Postman is a popular API client that makes it easy for you to create, test, and share API and automation workflows. This is done by creating and saving a number of API requests in the form of collections. You can simply use them over and over again, without having to remember the exact endpoint, attributes, API token etc. As a result, you will work more efficiently and spend less time on tedious details.