You are here

How to Use Postman as a Data Pump for Testing

Working with your API in a test environment can be a pain. Generating fake calls to test the API can require manually fiddling with things like urls, causing errors and frustration. Tom Wright over at his blog thinks he’s found the solution.

Tom explains that in his job as a developer he has to test sales processing pipelines. For testing he has to generate fake orders with API calls. He had been doing this with Fiddler, a network debugger. The problem with this was that he had to manually change urls for calls between dev and test environments, manually launch a login script and manually update variables in the body of the call every time. 

Frustrated with his progress, Tom discovered Postman, an API building and testing tool early this year. Because it’s not a network bugger, there’s no painful configuration every time he wants to use it. Even better, Postman lets you use variables. These variables can be referenced everywhere and are scoped to the relevant environment. As a result, you can set variables in pre and post-call scripts to save time manually updating variables in different calls. This cuts out all the manual labor associated with Fiddler. You can set root urls for each environment in variables and you can add a postscript to the login call so that the access token is immediately available to all subsequent calls. 

You can also use pre-request scripts to update variables for use in the API call body. Simply write the callback function, assign the output to a variable and use curly brackets in the JSON body so that the right value will be assigned in the body at run time. 

Tom concludes by stressing that the Postman variables save him, and could save you, considerable time and frustration testing your API calls. Postman is a freemium product but all the functions that you need here are available with the free version. 

Be sure to read the next Testing article: How Meltwater Used RSpec to Test Its NGINX API Gateway

Original Article

Using Postman as a data pump for testing (instead of Fiddler)