Last reviewed against v0.9.0
source:
internal/tools/http_scripts.go Scripts and tests
Pre-request and post-response scripts in a sandboxed JS VM. Postman-compatible API. Test results inline below the response.
Pre-request and post-response scripts run in a sandboxed JS VM (goja) with a Postman-compatible API:
// Pre-request
pm.environment.set('signed_at', Date.now());
pm.request.headers.add({ key: 'X-Signed-At', value: pm.environment.get('signed_at') });
// Post-response
pm.test('Status is 200', function () {
pm.expect(pm.response.code).to.equal(200);
});
pm.test('Has user id', function () {
pm.expect(pm.response.json()).to.have.property('id');
});
Available helpers
pm.environment.set/getpm.request.headers.add/upsertpm.test(name, fn)pm.expect(value).to.equal/.to.have.status/.to.have.property/.to.includepm.response.code,pm.response.json(),pm.response.headers.get
Test results render inline below the response body with green/red badges.
Round-trip
Scripts are part of the saved-request shape — they round-trip through Postman v2.1 import and reverse export.