Pre-request scripts
A pre-request script runs before the request is sent — it is the first step of the send pipeline. It can:
- read and modify the request method, URL, body, and headers (
fp.request.*); - read and write environment variables (
fp.environment.get/set), which are persisted after the send; - stash ephemeral values for the post-response phase (
fp.variables.get/set); - emit logs (
fp.log/warn/error); and - define tests (
fp.test).
fp.environment.set('token', 'abc');fp.request.headers.set('Authorization', `Bearer ${fp.environment.get('token')}`);Scripts run inside an isolated, synchronous sandbox with a single global, fp. See the
execution model for the full API and its constraints.
The sandbox guards against accidental footguns, but it is not designed to contain a malicious
script. Treat a .http file from an untrusted source the way you would treat a shell script from the
same source: read it before running it.