

Finally, the code on the right side should evaluate to a boolean. The string key you pass in is the description that will be displayed whenever the tests are run. “tests” is an object that Postman uses to keep track of the tests it needs to execute. Tests should be written in the following format:

In the example above we use it to grab the Content-Type header from the response.Įverything written in this area is in JavaScript, so it’s easy to jump right in and start writing. It also offers a ‘postman’ object which has a number of utility methods on it. In addition, Postman gives us access to data like the response code, easily accessible through the “responseCode” object we are given. Here we can see that the request/response data are given to us by Postman and can easily be parsed out to use in tests. Each request that you write has an area where you can access the request/response data and use them to write tests for your requests like so: One of the areas that really shines in Postman is the built in testing capabilities that it offers. I’ve found these to be useful time savers when developing spinning up requests. Instead of manually creating these requests, I can create environment “profiles” in which I set up some key/value pairs of data like this:īy making one for each environment I can insert the values as variables in the format ” will generate an integer between 0 to 1000. I’ve got two requests to the same endpoint that are in different environments. However, Postman makes this easy with its use of Global Variables and Environment Variables.įor instance, let’s look at this example where I am attempting to retrieve a post object from an endpoint while passing an Authorization header: It was tedious to make the same request to multiple environments, because I’d have to be switch data all the time. Each environment has its own auth token, its own url, and maybe its own headers. One pain point for me when doing API development was working with multiple different environments. Postman gives us the option to share a direct link or even generate some code for embedding a button/link to the collection in a website! To share an API call all you have to do is select the “…” menu on a collection and select “Share”. It saved us a lot of headaches when debugging issues in the long run. In addition, if they ran into any issues while testing, they could easily send us the request they were using so we could recreate the exact call ourselves. Once we were done building our endpoints and turned the work over to QA, we were able to share our API calls with them so they could get a good look at how the APIs were supposed to function and what the calls looked like.

This was also invaluable when working with our QA team. Within seconds I had access to all his API calls without having to manually enter them in. Rather than having to check the docs and manually build the correct request, he was able to generate a link for his request collection that I was able to import into Postman. (More on that later in the post!)įor example, while I was developing an API with a coworker, there were many times when we needed to access several REST calls that the other had been working on. These collections are convenient ways to organize, share, and even test all my requests. In addition to exporting a single request that way, I can also label and save my requests to collections that I can share with anyone who uses Postman. This way I can easily take one request and put it in whatever code I am working with! Postman offers us a number of options for how we choose to enter in this information, but it also allows us to generate code snippets for multiple different languages that would also make this call: Here at our basic request screen we can select our request type, set our headers, fill our the request body, and do all the other basics that we’re familiar with. The basic interface of Postman is probably similar to ones you’ve seen before: I wanted to create this blog post as a quick Postman primer, to showcase some of its shining features. It’ very easy to use despite its depth of features, and I find myself discovering new ways to use it very often.
#POSTMAN REST API EXAMPLE MAC#
Īvailable as a Chrome extension, as well as a Mac application, Postman is a robust, multi-featured application that helps you build, test, and share REST API calls easily. There are a multitude of services out there that seek to help with this problem, and while sifting through them I found one that has exceeded my expectations: Postman.

Recently at one of my clients, I found myself looking for a different setup for building and managing REST calls to various APIs I was working with.
