0
0
Postmantesting~20 mins

Request headers in Postman - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Request Headers Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding the purpose of request headers

Which of the following best describes the main purpose of HTTP request headers in API testing?

AThey carry metadata about the request such as content type, authorization, and caching policies.
BThey contain the actual data payload sent to the server in the request body.
CThey specify the IP address of the client making the request.
DThey define the server's response format and status codes.
Attempts:
2 left
💡 Hint

Think about what extra information is sent along with the request but is not the main data.

Predict Output
intermediate
2:00remaining
Output of a Postman test script checking a header

Given the following Postman test script, what will be the test result if the response header Content-Type is application/json; charset=utf-8?

Postman
pm.test('Content-Type is application/json', () => {
  pm.response.to.have.header('Content-Type', 'application/json');
});
ATest fails because the header value does not exactly match 'application/json'.
BTest passes because the header contains 'application/json' as part of its value.
CTest fails because the header 'Content-Type' is missing.
DTest passes because Postman ignores charset in header value comparisons.
Attempts:
2 left
💡 Hint

Check if the test checks for exact match or partial match of the header value.

locator
advanced
2:00remaining
Best practice for locating a header in Postman test scripts

Which of the following is the best way to check if the Authorization header exists in a Postman response?

Apm.response.headers.get('Authorization') !== undefined
Bpm.response.headers['Authorization'] !== null
Cpm.response.headers.find(header => header.key === 'Authorization')
Dpm.response.headers.has('Authorization')
Attempts:
2 left
💡 Hint

Look for the method designed to check header existence directly.

assertion
advanced
2:00remaining
Correct assertion for checking JSON content type header

Which Postman test assertion correctly verifies that the Content-Type header starts with application/json (ignoring charset)?

Apm.expect(pm.response.headers.get('Content-Type')).to.include('application/json');
Bpm.expect(pm.response.headers.get('Content-Type')).to.match(/^application\/json/);
Cpm.expect(pm.response.headers.get('Content-Type')).to.equal('application/json');
Dpm.expect(pm.response.headers.get('Content-Type')).to.be.a('string');
Attempts:
2 left
💡 Hint

Think about how to check the start of a string with possible extra text after it.

framework
expert
3:00remaining
Handling dynamic request headers in automated tests

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?

AHardcode a fixed UUID value in the header for all requests to keep tests consistent.
BAdd the UUID generation logic in the Tests script after the request is sent.
CUse a Pre-request Script to generate a UUID and set it as an environment variable, then reference it in the header value.
DManually enter a new UUID value in the Headers tab before each test run.
Attempts:
2 left
💡 Hint

Consider when and where to generate dynamic data before sending the request.