Autogenerating the Date Header in Postman

Featured image for sharing metadata for article

If you're working with APIs there is a chance you may be using Postman to interact with it.

The APIs you're interacting with may require the Date header, to know at what point in time the request has originated. Most HTTP clients, Postman included, will not send this by default, so we need to do a little bit of work to get it sending.

Also, because it's very likely important what date is used, we should generate it each time. Fortunately, we can use Postman's pre-request scripting with its JavaScript support, following [MDN's documentation] to generate a compliant (modern) date format:

pm.globals.set("dateHeader", new Date().toUTCString()); // => Wed, 29 Apr 2020 16:50:34 GMT

Then in Postman, we can reference this variable in our header as {{headerValue}}.

Written by Jamie Tanna's profile image Jamie Tanna on , and last updated on .

Content for this article is shared under the terms of the Creative Commons Attribution Non Commercial Share Alike 4.0 International, and code is shared under the Apache License 2.0.

#blogumentation #postman.

This post was filed under articles.

Interactions with this post

Interactions with this post

Below you can find the interactions that this page has had using WebMention.

Have you written a response to this post? Let me know the URL:

Do you not have a website set up with WebMention capabilities? You can use Comment Parade.