Advanced Postman

Postman is an application that lets you easily test API endpoints. Some of the more advanced or lesser known features make it very powerful and really speeds up workflow.

Each API endpoint is saved under a parent collection. Login endpoint test checks the response code and sets an authentication token in an environment variable.

As you can see above I have a request setup and saved for every endpoint in the application I am currently developing. Instead of re-typing a new request every time I setup a collection, which can be thought of as the parent.

Another powerful feature are environment variables. In the top right of the image you can see I am under my dev environment. In my requests, I use {{url}} (Postman uses {} to read variables), which is the environment variable I have set under dev. It’s value is localhost:3000. If I switch to production, I would use my Heroku server instead of localhost. This environment is applied to every single request saved under the collection. This is a huge time saver. Instead of replacing localhost for every endpoint, I can just make one switch in a drop-down list to switch in between dev and prod.

This specific app I have been working on also uses authorization tokens. When I login I want that token set. If the token is not set, I cannot test my endpoints that require authentication. In the test script above we check if the response code that Postman receives is 200 (201 for account creation). If the response code is correct, we grab the token and set it as an environment variable in Postman.

I have a default authorization method setup for my collection that uses the environment variable holding the token. If I want to tell Postman an endpoint requires authentication, I can tell it to inherit from parent. This prevents me from having to repeat myself for every endpoint that requires authentication.

It is late and this is probably poorly written. The point of the post is to encourage people to check out and learn Postman.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.