Which of the following best describes the main purpose of HTTP request headers in API testing?
Think about what extra information is sent along with the request but is not the main data.
Request headers provide metadata about the request, such as content type, authorization tokens, and caching instructions. They do not contain the main data payload or server response details.
Given the following Postman test script, what will be the test result if the response header Content-Type is application/json; charset=utf-8?
pm.test('Content-Type is application/json', () => { pm.response.to.have.header('Content-Type', 'application/json'); });
Check if the test checks for exact match or partial match of the header value.
The test checks for an exact match of the header value 'application/json'. Since the actual header value includes charset, it does not exactly match, so the test fails.
Which of the following is the best way to check if the Authorization header exists in a Postman response?
Look for the method designed to check header existence directly.
The has method is the recommended way to check if a header exists in Postman response headers. Other options may cause errors or are less direct.
Which Postman test assertion correctly verifies that the Content-Type header starts with application/json (ignoring charset)?
Think about how to check the start of a string with possible extra text after it.
The match assertion with a regular expression checking the start of the string is the best way to verify the header starts with 'application/json', ignoring charset or other parameters.
In an automated API test suite using Postman, you need to send a dynamic X-Request-ID header with a unique UUID for each request. Which approach is best to implement this?
Consider when and where to generate dynamic data before sending the request.
Using a Pre-request Script to generate a UUID and store it in an environment variable allows the header to have a unique value each time the request runs. This is the best practice for dynamic headers.