0
0
Postmantesting~10 mins

POST request 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 set the HTTP method to POST in Postman.

Postman
pm.request.method = '[1]';
Drag options to blanks, or click blank then click option'
APOST
BGET
CPUT
DDELETE
Attempts:
3 left
💡 Hint
Common Mistakes
Using GET instead of POST
Using PUT or DELETE which are different HTTP methods
2fill in blank
medium

Complete the code to add a JSON body to the POST request in Postman.

Postman
pm.request.body.raw = JSON.stringify([1]);
Drag options to blanks, or click blank then click option'
A{name: "John"}
B'name: "John"'
C{"name": "John"}
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a string that is not valid JSON
Using single quotes instead of double quotes in JSON
3fill in blank
hard

Fix the error in setting the Content-Type header for a JSON POST request.

Postman
pm.request.headers.add({key: 'Content-Type', value: '[1]'});
Drag options to blanks, or click blank then click option'
Aapplication/xml
Bapplication/json
Ctext/plain
Dmultipart/form-data
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'application/xml' or 'text/plain' for JSON data
Omitting the Content-Type header
4fill in blank
hard

Fill both blanks to correctly check the POST response status and parse JSON body in Postman test script.

Postman
pm.test('Status code is [1]', () => {
  pm.response.to.have.status([2]);
});
Drag options to blanks, or click blank then click option'
A200
B201
Cpm.response.json()
Dpm.response.code
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for status 200 instead of 201 for POST
Using response body parsing instead of status code check here
5fill in blank
hard

Fill all three blanks to extract a field from JSON response and assert its value in Postman test script.

Postman
const responseData = pm.response.[1]();
pm.test('Check user name', () => {
  pm.expect(responseData.[2]).to.eql('[3]');
});
Drag options to blanks, or click blank then click option'
Ajson
Bbody
Cname
Dusername
EJohn
Fjohn_doe
Attempts:
3 left
💡 Hint
Common Mistakes
Using pm.response.body() which returns raw text
Checking wrong field name or value