While working with POSTMAN , we need to validate many headers and values as part of API testing.
We can validate API response and Headers using javascript under TEST tab.
Please note that POSTMAN comes with two variants:
1- Chrome extension (Deprecated but still can be used)
2- Desktop application (Recommended)
We will discuss the examples in both variants.
1- Validate a header has expected value
//POSTMAN Desktop App
pm.test("Cache-Control is correct", function() {
pm.response.to.be.header("Cache-Control", "no-cache");
});
//POSTMAN - Extension
tests["Cache-Control is correct"] = postman.getResponseHeader("Cache-Control","no-cache");
2- Validate Header is present
//POSTMAN Desktop App
pm.test("Cache-Control is present", function() {
pm.response.to.have.header("Cache-Control");
});
//POSTMAN - Extension
tests["Cache-Control is present"] = postman.getResponseHeader("Cache-Control");

For JSON Schema validation check this post