What we will learn in this post:-
- Introduction to Header Presets
- Usage of Header Presets
- Creating and using Header Presets
- Managing Header Presets
Let’s think of a scenario before we jump to the concept of header presets.
Suppose you need to add multiple headers or a set of headers to each request or different set of groups of headers for different set of requests. You may be thinking of explicitly adding in to each requests. Is it not really boring and irritating and time consuming process?
If we could create different groups of headers which we can call wherever needed, will solve our problems. We have a similar readymade solution in Postman called Header Presets.
Header Presets is a group of headers which stores each header and its value as a key – value pair. You can use it quickly to add groups of headers to the request.
Let’s create a Header Presets:-
When we navigate to “Headers” tab of any request, we see a control called “Presets” as shown below:-
Click on “Presets” control. It will show an option called “Manage Presets” as a dropdown. Click on “Manage Presets“. You will see a dialog box as shown below:-
Click on “Add” button. Give name to Presets and add some headers with value and click on “Add” button.
It will list given header presets name ( “Sample Header Presets” as shown above). You can add multiple header presets like this. You can delete presets by clicking on cross sign as shown below.
You can update presets by clicking on its name.
So we have learnt to create/ Update and Delete header presets. Now time to learn its usage.
How to use created Header Presets:-
Navigate to “Headers” tab of a request and just type the name of Header presets in key text box. I have given name as “Sample Header Presets” so I will start typing character by character. All presets suggestion will be listing in dropdown with prefix as “Header Presets”.
Just click on that name. You will see all headers are added to request as individual at once. Remember it does not add headers as a reference. In programming term, It is call by value not call by reference.
There is another way to add presets. Click on “Presets” control at Header tab. It will show an option called “Manage Presets” and all created presets in dropdown. Select whatever you want to add.
Now you can add, edit , remove headers as we do normally. It will save a lot of time.
Drawbacks of Header Presets:-
As it does not populate headers as reference, it limits advantages of presets. Some drawbacks are given below:-
- If you want to update header value in presets, updated value will not be reflected automatically in request where presets were added earlier.
- Once you add presets in a request, there is no provision to remove headers of a selected presets.
We can use global or environment variables for key and value in header presets. This solves the problem of managing presets to some extent. Example is shown below:-