Scripting (Developer View)
Pre-send / post-response scripts are Quick Request's Swiss army knife: dynamic signing, encryption & decryption, conditional assertions and cross-request value passing all live here. Scripts are written in JavaScript and run in the built-in QuickJS engine.
This page covers only what you can add in the UI and what scripts can do; for the full JavaScript API signatures see the Script API Reference.
One Request Has Two "Action Chains"
On the request editor page you can add several steps to the pre-send and post-response chains; they run in order. Each step is one of:
| Step type | What you do in the UI | Typical use |
|---|---|---|
| Script | Write a piece of JavaScript | Change headers/body, signing, decryption, conditional logic |
| Library script | Reference a saved shared script | Reuse "inject token", "unified logging" in many places |
| Extract | Take a value from the response and store it as a variable | Pass the login token to the next request |
| Assert | Add one validation against the response | Status code = 200, a field exists |
| Wait | Pause for some milliseconds | Rate limiting, polling intervals |
How to Write Scripts: Two Entry Points
The script engine looks for well-known entry functions in your script:
// Pre-send: can change "the request that is about to go out"
async function onRequest(context, url, request) {
// e.g. inject a header
request.headers.set('X-Trace-Id', $uuid.v4());
return request; // you must return the request
}
// Post-response: can read and change "the response you received"
async function onResponse(context, url, response) {
// e.g. rewrite an encrypted response back to plaintext for humans
return response;
}
- Write
onRequestin the pre-send chain,onResponsein the post-response chain. - The function names must be exactly these, otherwise the script is treated as "no entry point" and skipped.
awaitis supported.
What Scripts Can Change
Changing the request (the request object in onRequest)
| You want | How |
|---|---|
| Set / override a header | request.headers.set('Authorization', 'Bearer ' + tok) |
| Add / change a query param | request.queries.set('ts', String(Date.now())) |
| Read the raw body | var text = request.body.parseText() or request.body.parseJSON() |
| Rewrite the whole body | request.body = the new string (plain assignment) |
Reading / changing the response (the response object in onResponse)
| You want | How |
|---|---|
| Read the status code | response.statusCode |
| Read a response header | response.headers.get('Set-Cookie') |
| Read the body | response.body.parseJSON() / .parseText() |
| Rewrite the whole response body | response.body = the new string — the UI/result view shows the rewritten content (verified) |