When should I use a script?
Use scripts for branching, combined transformations, or scheduled automation. Prefer rewrite rules for straightforward header, body, or mock changes.
Manual
When a simple rewrite is not enough, NetPeek scripts can run JavaScript before requests, after responses, or on a schedule, while constants keep reusable environment URLs, tokens, and other values in one place.
When rules aren't enough, use JavaScript to handle matched requests more flexibly: read/rewrite request & response, gunzip bodies, compute values conditionally. Scripts are scoped by host and run in the tunnel, like rules.
$utils provide gzip/gunzip etc.).Store frequently-used values (a mock JSON, a token, a test URL) as constants and reference them in rules with ${constantId} — change one place, update everywhere.
Rewrite rules cover static substitution. Scripts are for the cases that need a decision or a computation:
Use scripts for branching, combined transformations, or scheduled automation. Prefer rewrite rules for straightforward header, body, or mock changes.
A script runs only when that script is enabled and the global Scripts gate is on.
Constants centralize reusable values such as API endpoints or tokens so rules and scripts can share them.