A GOOD START WITH POSTMAN
Introduction Testing a backend API is one of the most important part of its creation. Postman let you create all the urls you need and test behavior of each one. But it can be very time consuming. Let's see some usefull tips to save time (and money).
Default use of Postman On the first launch, you arrives on a screen like this (depending of your version) :
Then, to run request, you only need to set his type (GET, POST, etc.) (1), his URL (2), his potential headers and parameters (3) and run it (4).
It is how Postman works, and it does it efficiently. But we easily understand why it can be time consuming. For each request, you have to enter URL, headers and parameters.
Environments & Variables For instance, setting the domain name for each new request can be boring really quickly. What if we had a tool to spare that ? You know what ? We have ! We call that Environnement and Variables. Click upper-right corner allow you to access this feature :
Instead of putting domain name directly into url, you can specify it in environment variables :
Select your newly created environment in the dropdown to make all environment variables accessible for Postman from now. You can switch between environment as you want (for instance, switch between dev and prod environment). Then, you only need to use variable (here : {{domainName}}) in URL field, and Postman do the rest. Every time you run the request, Postman will replace this variable by the content you set.
It becomes very handy when, for instance, you have to use an API and it requires to login (mostly to retrieve a token), and then you should use this token on each other request. Setting this token in environment variables make it public from everywhere in Workspace (see Workspace).
Workspace management If you are on several projects at the same time, or if you are a clean'up kind, it can be interesting to gather all request of a project at the same place. Postman allow you to do so in Collection's view :
But it allows you to do so much better. Workspaces ! A Workspace is by definition a space for one work. Yes, it's a project ! :) A Postman Workspace can be easily share between colleagues and has it own environment variables. To access them, you need to click on top of the screen on My Workspace (You have to sign in first). Then, you can set your Workspace a name (Localhost for instance), and specify if it is a public (Team)' or private (Personal) one. Caution there, free version of Postman don't allow you to share more than 25 request with your team.
Useful Script A powerful tool allow you to load environment variable just after a request has been executed. Assuming you received a response like this one from a login call : { "id": 1, "username": "admin", "token": "12345abcdef" } To automatically set token to environmenet variable, just go to Tests tab of login request, and enter this code : var data = JSON.parse(responseBody); pm.environment.set('token', data.token); This code will parse the JSON response and set token environment variable right after login complete. The token will now be accessible for all other request of you Workspace by calling it {{token}}.
Last words As you may have seen, Postman can be a very powerful tool. We hope these few tips will help you saving time with Postman, and allow you to concentrate on your real job, coding ! Stay tuned for new post about Postman in the future!