GuideRewrite & network
Rewrite action
Let the real request go out and rewrite only the parts you configure — declaratively or with hooks.
The Rewrite action sends the real request and rewrites only the parts you configure — the page still talks to the real backend, which is what you want when a proxy or a shared dev server is the target. Two modes exist and they are mutually exclusive.
Declarative rewrite
| Target | What you can do |
|---|---|
| URL | Find & replace groups; the find part is a literal or a regex, the replacement can reference capture groups with $1, $2… |
| Query params | Add, replace or remove entries by name. |
| Request headers | Set lines of header names and values. |
| Request body | Find & replace groups, applied in order. |
| Response headers | Same as request headers, on the way back. |
| Response body | Find & replace groups, applied in order. |
Groups are applied in the order they are listed. Each group can be a plain literal (fast, no escaping) or a regex with $1-style capture references — enable Regex on the group to use the latter.
Hooks
Hook mode runs your code instead. A request hook can change url, headers and body; a response hook can change status, statusText, headers and body. The function body receives a single context argument; return only the fields to change — everything you omit keeps its original value. Both hooks can be used together, and context.req in the response hook already includes the request-hook changes.
// context.req — { url, method, headers, query, body, params }
// Only url / headers / body are read from the return value
return {
headers: { ...context.req.headers, 'x-env': 'test' },
};// context.res — { status, statusText, headers, body } (body parsed when JSON)
// context.req — request context, request-hook changes included
// context.loadFaker() — loads Faker (en / fr / de / ru)
return {
headers: { ...context.res.headers, 'x-mocked-by': 'mockrew' },
};method, query, params for requests; anything but status / statusText / headers / body for responses) are ignored — change the URL instead of the method, and use the query table for parameters.
Stuck, or need something clarified? support@mockrew.com·Terms of Service