Before scripts run immediately before Postchi sends a request. You receive the request object and can mutate it freely — whatever state it’s in when the script finishes is what gets sent.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.
File naming
Place a file named<request-name>.before.js in the same folder as your request file:
before.js in that folder:
The folder-level
before.js runs first, then the request-level <name>.before.js. This means the request-level script always sees changes made by the folder-level script.Available context
Postchi injects these variables into every before script:| Variable | Type | Description |
|---|---|---|
request | object | The request about to be sent. Mutating this object changes what Postchi sends. |
env | object | All active environment variables as string key-value pairs. Read-only. |
fetch | function | The global fetch function. |
The request object
| Property | Type | Description |
|---|---|---|
request.method | string | HTTP method, e.g. "GET" |
request.url | string | Full URL including any template variables already resolved |
request.headers | object | Headers as { name: value } pairs |
request.body | string | null | Request body as a string, or null |