Mallow's Blog

Postman Environment Setup For Laravel API

Postman is a forum for API development (Application Programming Interface), the forum can be used to develop the API during the development process and also to test it with development teammates. 

The following information will provide the basic steps for setting up environment for API development.

Workplace and Collection:

Workplace is the first step in the process. For the development process, we will create multiple workplace. We can use collection in workplace, because in the development stage we’ll build more than one API request(s). We can record all the API requests by using the collection and group them to a folder structure. You may build the workplace for personal use or for team development.

We can create the new workspace from the top bar of the postman as well as from the left sidebar in the new collection layout.

Create new workspace from the top bar

Environment In Postman:

The next configuration in the postman tool is Environment. For the requests, the postman environment uses multiple key and value pairs.The key(s) can be used as variables for the environment. We can create the variables as local or global. The variable(s) are also trackable and modifiable. We can access variables throughout postman. The environment setup provides option to create many environments with various variables. It has local and global variable support. The local scope variables will work within the selected environment. But the global scope variables will work outside the environment.

Setting Up Environment Variable With Laravel API:

Here we will have a look at the setup of the environment variable and the laravel framework will be used for the example purpose. The laravel framework based on php facilitates the developers for Web and API development process. The laravel’s intent in the development of the API has the file “api.php” (under the routes folder).

We can use the environment option (we can see it in the right side of the top bar in the postman) to create the API process variable.

Use Environment Option

We may use this option in the development process for the repeated use of values. Both variables can be controlled and modified if need occurs.

For example we must authenticate the users by validating their authentication before accessing our project data through the APIs. Every time we don’t ask for credentials from the user to verify them. We’re just giving them one token to access our API and the data here in the environment. We can store the authenticated token and use that variable for all the requests.

Access and Modify Variables:

Use the double curly brace (“{ } “) to enclose the element. Use” { { url } } “(url key with double curly brace) to retrieve the url name. The variables can be accessed in header, body and so on of requests.

Use Double Curly brace I
Use Double Curly brace II

For example, (Request body in the JSON format)

    “name”: {{name}}

Every time we don’t change environment variable values. We can also alter the values from the answers to requests. It will affect the actual key value to the environment. This option is available in the “Test” option using the scripts.

Alter the values

For example, (Test Script)

var jsonData = JSON.parse(responseBody);
postman.setEnvironmentVariable("token", jsonData.token);

We’ve seen the local and global scope environment variables already. We have two methods to modify them from the script and they are setEnvironmentVariable() & setGlobalVariable().

Benefits Of Environment Variables:

When we start to use the collection and environment of postman, with development, testing, and production data it is easy to test the same set of APIs. For this easy option, we can set up separate environment with the single collection as well. It will reduce the time for the developer to test multiple values with the API collection that has been developed.

Hope you would have got an idea on the steps to set up environment for API development. We shall look into some other interesting topics in the upcoming blogs.

-Ramadurai M,
PHP Team,
Mallow technologies.


  1. walker smith

    My objective with this Laravel instructional exercise to make a guide for those simply learning Laravel. This guide will take you from the earliest starting point of a thought into a genuine deployable application.

  2. Miley Cyrus

    Thanks for sharing these tips! I am sure your tips really helpful!

Leave a Comment

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