Supercharge Your Productivity with Postman!
Tags: productivity, postman, api, programming
Published: 2023-06-13 12:54:12

Before we get started talking about how you can improve your productivity and workflow, let's have a look at what Postman is. 

**Postman** is an API Platform for developers to design, build, test and iterate their APIs.

Now that we know what Postman is, let’s have a look at how we can improve your productivity!

---

### 1. Collections

A collection is a group of requests which are connected to the same API. Using these we can easily organize our HTTP requests into separate folders so that we know which one does what.

#### Creating collections

1. Select **Collections** in the sidebar, then select **+**.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7ovaa5czvlix1xn04czy.png)


2. Select **New**, then select **Collection**.

3. With **Collections** open in the left sidebar, select **+**.

4. In an empty workspace, select **Create Collection**.

5. You can also [create a collection from a template](https://learning.postman.com/docs/collections/using-collections/#using-collection-templates).

&nbsp;

### 2. Setting and Using Variables

Variables enable you to store and reuse values in Postman. By storing a value as a variable, you can reference it throughout your collections, environments, requests, and test scripts.

#### Setting and using variables

1. Highlight any part of the URL in the request that you want to set as a variable, then click **Set as variable**.
![Postman - setting a new variable](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hjaveatyqy723kf26i3i.png)

2. Now, click **Set as new variable** and set the following information:
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mox5mnf10ms6h73tpgcn.png)

3. Now click **Set variable** and you are done setting a variable!
    
4. To use the variable, replace your the URL in the request with your variable.
    
```bash
http://localhost:5000/api/v1/status => {{baseUrl}}/status
```
    
&nbsp;
    
### 3. Editing Variables
    
To edit a variable, do the following: **(You can also add variables here)**
    
1. Hover over your collection name and click the **hotdog menu**.
![Postman - editing an existing variable](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/og2uphm0ir69x47am826.png)
 
2. Now, click the **variables** tab
![Postman - editing an existing variable](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4o0cvlle2sobgrnlbt9d.png)

- Variable:
    - The name of your variables
- Initial value:
    - This value is shared with your team when you share the variable in a collection, environment or globals.
    - **Example:** If you share this collection with anyone, they will be able to see the **Initial value**
- Current value:
    - This value is used when sending a request
    - This is what is currently being used in Postman and is private to use

&nbsp;  

### 4. Postman variables (Global, Environment)

Global and Environment variables work just like regular variables but with Global variables you can use the variable across all of your collections and with Environment variables you can use it depending on what environment (development, production) you are on.

To create and use a **Global** variable, do the following:

1. Select the environment **quick look (eye) icon** on the top right of the screen.

2. Next to **Globals**, select **Edit** (or **Add** if no variables have been added yet).
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/huz7uk8g31haxhv5yoxb.png)

3. Add a variable named `baseUrl` and give it an initial value and a current value of `https://simple-books-api.glitch.me`.

4. Open a new request tab and enter `{{baseUrl}}` as the URL. Hover over the variable name to inspect the variable's value and scope.

To create and use an **Environment** variable, do the following:

1. Select **Environments** in the sidebar, then select **+**.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uss850g0tyla2ltxrh1q.png)

2. Rename the environment to `ProjectName - Development` or `ProjectName - Production`

3. Add a variable named `baseUrl` and give it an initial value and a current value of `https://simple-books-api.glitch.me`.

4. To use the environment, select No Environment at the top right of the screen and then choose the environment that you just created.

&nbsp;

### 5. Bonus Tip

Have you ever been in a situation where, when you authenticate a user using a login endpoint such as `/auth/login`, you have to keep copying and pasting the **Bearer Token** into your other endpoints to be able to use them?

Well, to solve that issue, it is quite easy. To help you stop wasting time and to auto populate the token for you, you will have to do the following:

1. Find your login endpoint, in this case we will use:

```bash
{{baseUrl}}/auth/login
```

2. Input your username/password into the Body in JSON format.

3. Click on the tab **Tests** and set the following information:

```javascript
const json = JSON.parse(responseBody);
postman.setEnvironmentVariable("token", json.token);
```

4. You are done! Now whenever you send a HTTP request to your login endpoint, it will set/update the environment variable for **token**.

&nbsp;

### Thanks for reading!

Have a question? Connect with me via [Twitter](https://twitter.com/dylansleith) or send me a message at hello@dylansleith.com