As it's website introduces Postman is the most complete toolchain for API development
Click the gear icon and choose Manage environments.
Link: https://www.getpostman.com/docs/postman/environments_and_globals/variables
Create variables for environments, e.g.:
| key | value |
|---|---|
| google_url | http://google.com |
| key | Postman |
| content_json | application/json |
You can use it in your requests, for e.g:
- Request URL:
{{google_url}}/?q={{key}}, meanshttp://google.com/?q=Postman - Headers: Content-type:
{{content_json}}
Postman has those auto generated variables:
{{$guid}}: Adds a v4 style guid{{$timestamp}}: Adds the current timestamp{{$randomInt}}: Adds a random integer between 0 and 1000
Link: https://www.getpostman.com/docs/postman/scripts/test_scripts
You can write tests for result by javascript:
function isNumber(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
}
var jsonData = JSON.parse(responseBody);
tests["Has response_code"] = jsonData.hasOwnProperty('response_code');
tests["response_code is numeric"] = isNumber(jsonData.response_code);
tests["Has message"] = jsonData.hasOwnProperty('message');
if (jsonData.hasOwnProperty('data')) {
tests["[Data] has age"] = jsonData.data.hasOwnProperty('age');
tests["[Data] has name"] = jsonData.data.hasOwnProperty('name');
tests["[Data] has address"] = jsonData.data.hasOwnProperty('address');
console.log("name: " + jsonData.data.name);
}
console.log(jsonData);For console.log or any similar command, you have to enable Developer Tools for Postman:
- Browse
chrome://flagson Google Chrome - Enable
Debugging for packed apps - Right-click on Postman screen, choose
InspectorCtrl + Shift + Ion Windows for short.
Link: https://www.getpostman.com/docs/postman/sending_api_requests/generate_code_snippets