DEV Community


Posted on

How to set global request header information in Postman

Postman is a powerful API development tool that not only allows users to send requests and test APIs but also enables them to set global request header information to ensure that each request contains the same header information every time it is sent. In this article, we will detail how to set global request header information in Postman.

What is Global Request Header Information?

In HTTP requests, header information contains important details about the request and response. Sometimes, we want to include the same header information with every request, and setting global request header information is useful for this purpose. By setting global request header information, we can ensure that each request includes pre-defined header fields and their corresponding values.

Steps to Set Global Request Headers

1.Open Postman and select or create a collection.

Make sure you have opened the Postman application. Then, in the left sidebar, select or create a collection where you want to add global request header information to organize your requests. Left-click on the chosen collection or click on the three dots next to the collection name and select the "Edit" option.

Image description

2.Add Global Request Header Information

In the collection settings page, you will see an option named "Authorization". Under this option, you can add some global request header information.

Image description

For example, if you have a login interface, and you have set the token credential of the interface via Tests script into an environment variable, now you want to apply this token credential to all interfaces under this collection. You can choose the Type as Bearer Token here and reference the token value from the environment variable using {{}}. This way, when requests are made by interfaces under the collection, they will automatically carry this token credential.

Image description

If you want to set other types of request headers, you can also click on the "Pre-request Scripts" tab to enter the request script page and write a script to add headers. In the request script page, you can write JavaScript code to add request headers. Here is an example code:

// Set global request header
    key: 'Authorization',
    value: 'Bearer your_access_token_here'

// Add other request headers
    key: 'Content-Type',
    value: 'application/json'
Enter fullscreen mode Exit fullscreen mode

Please note that you can modify the request header fields and values according to your needs in the above code.

Image description

3.Verify Global Request Header Settings

Now that you have successfully set the global request header information, to ensure that your requests are using these headers correctly, you can open any request and verify if they are included under the headers section. You can check by clicking on the request path in the Console.

Image description


Key steps in setting global request header information using Postman include adding the required header information to the collection settings page, ensuring the appropriate type and value are selected, adding additional request headers if necessary through JavaScript scripts, and finally verifying that the settings have taken effect.


Learn more:

Top comments (0)