mirror of
https://gitea.com/mcereda/oam.git
synced 2026-02-09 05:44:23 +00:00
2.5 KiB
2.5 KiB
Postman
API platform for building and using APIs.
Table of contents
TL;DR
Export environments:
- Select
Environmentsin the sidebar. - Select the one environment to export.
- In the workbench, select the more actions icon (the three dots).
- In the more actions menu, select Export.
- Choose a path and name to download a newly generated JSON file containing the chosen environment definition.
Export or update variables from responses using those responses' test scripts:
const responseJson = pm.response.json();
pm.environment.set("access_token",responseJson.access_token);
Scripting
You can execute JavaScript code:
- Before a request is sent to the server, as a pre-request script under the Pre-request Script tab.
- After a response is received, as a test script under the Tests tab.
Basic examples:
// Expect a specific status code.
pm.test("Response status code is 200", function () {
pm.response.to.have.status(200);
});
// Expect specific status codes.
pm.test("Response status code is 200 or 201", () => {
pm.expect(pm.response.code).to.be.oneOf([200,201]);
});
pm.test("Multiple assertions", () => {
const responseJson = pm.response.json();
pm.expect(responseJson.type).to.eql('vip');
pm.expect(responseJson.name).to.be.a('string');
pm.expect(responseJson.id).to.have.lengthOf('1');
});
// Export values from responses.
const responseJson = pm.response.json();
pm.environment.set("access_token",responseJson.access_token);
pm.globals.set("access_token",responseJson.access_token);
pm.collectionVariables.set("access_token",responseJson.access_token);
More examples here.
Further readings
- Website
- Documentation
- Insomnia, an alternative to Postman
- Newman, CLI Collection runner for Postman
Sources
All the references in the [further readings] section, plus the following: