0
0
Postmantesting~10 mins

Response headers in Postman - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to get the value of the 'Content-Type' header from the response.

Postman
let contentType = pm.response.headers.get('[1]');
Drag options to blanks, or click blank then click option'
AContent-Length
BContent-Type
CDate
DServer
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Content-Length' instead of 'Content-Type'.
Misspelling the header name or missing the hyphen.
2fill in blank
medium

Complete the code to check if the response headers include 'Cache-Control'.

Postman
let hasCacheControl = pm.response.headers.has('[1]');
Drag options to blanks, or click blank then click option'
AETag
BExpires
CCache-Control
DLast-Modified
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for 'Expires' instead of 'Cache-Control'.
Using lowercase or misspelled header names.
3fill in blank
hard

Fix the error in the code to correctly assert the 'Server' header value is 'nginx'.

Postman
pm.test('Server header is nginx', function () {
    pm.expect(pm.response.headers.get('[1]')).to.eql('nginx');
});
Drag options to blanks, or click blank then click option'
AServer
Bserver
CSERVER
Dservers
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase 'server' which may not match the header name.
Using plural 'servers' which is incorrect.
4fill in blank
hard

Fill both blanks to create a test that asserts the 'Content-Length' header is greater than 100.

Postman
pm.test('Content-Length is greater than 100', function () {
    pm.expect(parseInt(pm.response.headers.get('[1]'))).to.be.[2](100);
});
Drag options to blanks, or click blank then click option'
AContent-Length
Babove
Cbelow
Dequal
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'below' or 'equal' instead of 'above' for the assertion.
Not parsing the header value to an integer before comparing.
5fill in blank
hard

Fill all three blanks to create a test that asserts the 'ETag' header exists and starts with a double quote.

Postman
pm.test('ETag header exists and starts with a quote', function () {
    let etag = pm.response.headers.get('[1]');
    pm.expect(etag).to.not.be.[2];
    pm.expect(etag.startsWith('[3]')).to.be.true;
});
Drag options to blanks, or click blank then click option'
AETag
Bnull
C"
Dundefined
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'undefined' instead of 'null' in the assertion.
Forgetting to check the header exists before calling startsWith.