import statements or TypeScript. Postchi injects the context you need directly.
There are three types of scripts:
Before scripts
Run before a request is sent. Mutate the request’s method, URL, headers, or body.
After scripts
Run after a response is received. Extract values into environment variables or secrets.
Actions
Standalone scripts you run on demand. Execute requests, set variables, and chain workflows.
Script types
Execution order
When you send a request, Postchi runs scripts in this order:1
Folder before script
If a
before.js exists in an ancestor folder, it runs first and can modify the request.2
Request before script
If a
<request-name>.before.js exists next to the request file, it runs next with the (already-modified) request.3
Request is sent
Postchi sends the final request.
4
Request after script
If a
<request-name>.after.js exists, it runs first with the response.5
Folder after script
If an
after.js exists in an ancestor folder, it runs last with the same response.Both the folder-level and request-level after scripts share the same mutation state — all
setEnvironmentVariable and setSecret calls from both scripts are applied together.How scripts run
Scripts are plain JavaScript wrapped in an async function. Postchi injects variables into the function scope, so you can use them directly without declaring them:await anywhere since they run inside an async context.