Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.getpostchi.com/llms.txt

Use this file to discover all available pages before exploring further.

Postchi lets you attach JavaScript scripts to your requests and run standalone scripts on demand. Scripts run in a sandboxed async function — you don’t need 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

TypeFile nameWhen it runs
Before script<request-name>.before.jsBefore the request is sent
Folder before scriptbefore.js (in any folder)Before every request in that folder and subfolders
After script<request-name>.after.jsAfter the response is received
Folder after scriptafter.js (in any folder)After every request in that folder and subfolders
Action<name>.action.js (in actions/)On demand, from the actions panel

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:
// 'request', 'env', and 'fetch' are all available — no imports needed
request.headers['X-Request-Time'] = new Date().toISOString();
Scripts can use await anywhere since they run inside an async context.