Intro­ducing Postman

WTL - Lunch & Learn - API Entwicklung und Test mit Postman

Postman is a Chrome Add-On and Appli­cation which is used to fire requests to an API. It is very light­weight and fast. Requests can be organized in groups, also tests can be created with verifi­ca­tions for certain condi­tions on the response. With its features it is a very good and conve­nient API tool. It’s possible to make different kinds of HTTP requests (GET, POST, PUT, PATCH and DELETE). It is possible to add headers in the requests.

In this intro­duction I will write about more interesting features it has: Variables, Pre-Request Script, Environ­ments and Tests. At the end i will tell you how to share your requests with your teammates.

Variables

WTL - Lunch & Learn - API Entwicklung und Test mit Postman - Screenshot 1

There are two types of variables – global and environment. Global variables are for all requests, environment variables are defined per specific environment which can selected from a drop-down or no environment can be selected. Global variables are editable by small eye-shaped icon in the top right corner.

Once defined variables can be used in request with format surrounded by curly brackets: {{VARIABLE_NAME}}. You have autocom­pletion once you start typing the variable name.

Pre-Request Scripts

WTL - Lunch & Learn - API Entwicklung und Test mit Postman - Screenshot 2

Postman allows users to do some JavaScript coding with which to manipulate the data being sent with request. For example, you need to add an encrypted token to your request for authen­ti­cation, pre-request scripts enable you to do so. It can also be used to change the value of global or environment variables.

Environ­ments

WTL - Lunch & Learn - API Entwicklung und Test mit Postman - Screenshot 3

If you need to switch between different creden­tials this is where environ­ments come in play. By switching environment and with no change in the request you can send different parameters to API. Environ­ments are managed from Settings icon in the top right corner which opens menu with “Manage Environ­ments” link.

Lets say you develop on a local api, you define a {{DOMAIN}} variable for your local environment. In a later stage you need to request a staging api. Instead of duplicate all requests you just copy the local environment and change the value of the {{DOMAIN}} variable. All requests can now fred against diferent apis by switching environment.

Tests

WTL - Lunch & Learn - API Entwicklung und Test mit Postman - Screenshot 4

After response is received Postman has functio­n­ality to make verifi­ca­tions on it. This is done in “Tests” tab. There are a lot of prede­fined tests in postman on the right side of the active test tab. Many more can be found at: „https://www.getpostman.com/docs/v6/postman/scripts/test_scripts

Export/Import

WTL - Lunch & Learn - API Entwicklung und Test mit Postman - Screenshot 5To share your requests with other team members you have to save all requests in a collection and export this collection into a file. The other team members should import this file by clicking the „Import“ button on the top left of Postman. It makes sense to add this export file to your VCS. New features may demand new requests.