Postman CI/CD

Marco Fernandes
Runtime Revolution
Published in
3 min readJul 5, 2018

--

Postman is a powerful tool. Everyone that has worked with or developed an API has probably used postman and acknowledged its power.

It has a couple of features that I particularly like:

Having a shared repository of the most common endpoint calls in your project in a centralised place is an efficient way of having everyone on the team know how to use your own API

Shared collection — The more complex an API gets with all the different endpoints, params, and headers, the more the importance of this feature is revealed. Not everyone on the team is involved in developing of all the features of your product, so it is not mandatory to have all the different calls off the top of their head. Having a shared repository of the most common endpoint calls in your project in a centralised place is an efficient way of having everyone on the team know how to use your own API, or the API your product uses.

Testing — You can write tests for every request on your shared collection and run all the tests in a batch. I am not going to explain the benefits of having tests, that is common sense. Postman is packed with tv4 which makes it easy to write tests to verify that your API responses are compliant with the JSON schema.

Every information you have in Postman is exportable into a JSON file

Export — Every information you have in Postman is exportable into a JSON file. Requests, headers, environments, variables, tests, etc. Everything can be exported. Once you have a JSON file with all this data there is a lot of useful things you can do with it. You can share it with someone, for example, a potential customer that you want to demo your product to, a fellow developer that wants to add a new field to the request. You can store it in you repository, this way you can freeze with every GIT tag the requests your API had at that time.

The ability to run from the command line, in conjunction with the tests feature described above, means we can have test automation.

Newman — Newman is postman on your command line. This means that you can run all of the tests that you created in postman from a command line. The ability to run from the command line, in conjunction with the tests feature described above, means we can have test automation.

newman run <collection.json> --environment <environment.json>

Travis CI integration— Newman will return zero if all tests run with success or one if any of the tests failed. This is exactly what travis is expecting. This is a possible use of newman in travis setup file:

after_deploy: 
- if ! newman run integration_tests.json --environment environment.json; then echo -e Newman tests failed; travis_terminate 1; else echo -e Newman tests succeed; fi;

This article offers just a glimpse into all the features postman has. I, personally, like these ones and I use them frequently during development. When used all together, it allows you to use postman in your CI/CD. I hope this article helps you in developing and testing API. If you have any questions, please let me know!

I work at Runtime Revolution, where we focus on delivering and maintaining the best possible products to our clients, while learning the most we can along the way.

--

--