In Praise of Postman

In Praise of PostmanIf you need a quick, easy, and good-looking way to verify RESTful services, then Postman is your, um, man. Postman was initially created as a side-project by Abhinav Asthana in 2012, and is now supported by a fully-fledged dedicated company called Postdot Technologies. It is used by over 3.5 million developers and, if you’re not yet one of them, here are a couple of reasons why you should be.

Postman is downloadable as both a stand-alone app and as an in-browser Chrome app, although the latter has been marked for deprecation towards the end of 2017, in accordance with Google’s plans to end support for Chrome apps. There are Linux, Mac and Windows versions available.

The interface is an attractive and mostly intuitive one, although it does take some clicking around to find some of the functionality. There is an option of a dark or a light theme. The start-up messages are impressively technical (“Moving satellites into position…”, “Distorting space-time continuum…”), so your showcase audience should be suitably awed. And it is a perfect tool for showcasing the unglamorous world of REST APIs, with a zoom capability and neat partitioning of request and response messages, and colour-coding to differentiate name-value pairs.

On to the key capabilities that make Postman an attractive tool for me: multi-environment support, scripted variables, collections, header manipulation, and easy importing and exporting of configuration. Before we explore these capabilities, let’s check out how to get started.

Once you have installed and started Postman, you can either import a service definition file such as WADL, RAML, a Swagger file, or even a curl command, or you can simply type the end-point you want to invoke in the address bar, specify the type of command (GET, PUT, POST, etc) using the drop-down list, and then capture parameters and the request body as applicable. You can save the request in an existing collection, or create a new one; collections are essentially folders you can use to logically group requests. Adding new requests is as simple as clicking on the “Add new tab” icon.

Now, let’s get back to those capabilities.

Multi-environment support

In all but the most basic of set-ups, developers who are consuming services will need to do so across multiple environments. You may start off integrating with a development environment, and then move to a QA-appropriate environment as the implementation matures. Postman allows you to define multiple target environments, and parameterise variables such as hosts and ports. Thus, if the URLs for your services are “http://devhost.acme.com:8080/dostuff” and “https://qahost.acme.com/dostuff”, you would specify “{{host}}/dostuff”, then create two environments, Dev and QA, by clicking on the “Environment options” icon. Add a key-value pair “host”-“http://devhost.acme.com:8080” and “host”-“https://qahost.acme.com” respectively, and you can now switch between these at will, simply by selecting the target environment from the environment drop-down list. Any environment-specific parameters can be added as additional key-value pairs.

Scripted variables

Variables can also be used to persist response values across multiple requests. An example use-case for this is where your business services require authentication; you can create a request to perform the authentication, then store the resultant token as a global variable, which is then used in subsequent requests. To set or clear a variable before executing a request, select the “Pre-request Script” tab in the request panel. Frequently used snippets are provided in a pallet next to the capture area, and these will assist with syntax. To clear a global variable, for example, click the “Clear a global variable” snippet; this will result in the following JavaScript snippet appearing:
postman.clearGlobalVariable(“variable_key”);
Replace “variable_key” with the desired key, and you’re done!
Post-request scripting is defined in the “Tests” tab. This means you can evaluate results (which also enables you to pass or fail the result), and conditionally set variables. Again, snippets are provided for your convenience, with a richer selection than for pre-request scripting. Use the double-curly bracket notation (“{{variable_key}}”) in your URL, parameters, or body definition to indicate variable place-holders.

Collections

As alluded to above, collections are named folders containing related requests. These may be a sequence of requests that represent an end-to-end transaction, or identical requests with different parameters to verify conditional behaviour. Collections are very useful for organisation when you are dealing with a large number of requests. They can also be used as the container for running a sequence of requests, using the “Collection Runner” functionality.

Header manipulation

Service providers often use header values for meta-data about requests, which in turn may be used, for example, for audit logging, security, or behaviour tracking. When these headers are pre-requisites for a service, or an entire application, it is necessary for a testing tool to be able to provide them in the same way a “genuine” client would. Postman accommodates this with the “Header” tab in the request panel, where you can simply add name-value pairs, and use hard-coded values, or provide dynamic values using scripted variables.

Importing and exporting

Finally, it is really easy to share your magical request definitions with your colleagues. You can export requests, environments, or all of your configuration settings into a JSON file, which can then be imported by another user. To export requests, select the root folder of your collections or requests, and then click on the three dots to display the floating menu, then select “Export”. To export environment configuration, click on the “Environment options” icon, select “Manage Environments”, then select the “Download Environment” option next to the target environment. To export everything, click on the “Settings” icon, and select the “Settings” menu option, then select the “Data” tab, and click the “Download” button.

There is a large “Import” button in the toolbar to use to upload the files generated through these actions.

Conclusion

I have attempted to provide an insight into the functionality and features of Postman that I find useful, and use frequently. There are more features that I have not mentioned, such as monitoring, mocking, and extensive collaboration support. Some of these are available in the licensed versions, Postman Pro and Postman Enterprise. The documentation is comprehensive and comprehensible, and provides detailed instructions accompanied by illustrative graphics.

I enjoy using Postman to quickly verify the status of environments, to execute a set of requests to emulate a real-life scenario, to explore and unpack a new service provided by another team, to test my own service implementations, and to showcase the successful implementation of services we have created, using an attractive, professional interface.

I thoroughly recommend adding it to the arsenal of tools that you, as a developer, use on a daily basis.

Write a Reply or Comment

Your email address will not be published.