Rewrite HTTP Traffic and Mock APIs on iOS
A NetPeek rewrite combines match conditions with actions, letting you edit headers, replace bodies, mock a response, block a request, redirect traffic, or return a local file without changing the app under test.
3Rewrite rules (Simple mode)
Rewriting changes traffic without changing code: add headers, replace response fields, mock APIs, block ads, redirect. A rule = a condition (when it applies) + an action (what to do). Beginners use Simple mode — a few taps.
- Swipe a row in Recent Requests → "New rewrite" (host/path prefilled), or tap + in the rewrite list.
- When it applies: pick "All requests" or add conditions (host contains / path begins with …).
- What to do: pick one of six intent cards.
- Set the details: fill fields per intent. A plain-language summary updates live; confirm and tap Save & Enable.
| Intent | Use |
|---|---|
| Edit Header | Add / change / delete a request or response header |
| Edit Body | Replace a piece of text in the response/request body |
| Mock response | Skip the real request and return custom content |
| Block request | Return empty response / JSON / image — great for ad & tracker blocking |
| Redirect | Send the request to another URL (e.g. prod → staging) |
| Local file | Serve a file on the device as the response |
4Rewrite rules · Expert syntax (DSL)
Expert mode lets you write the rule statement directly for full power. The first symbol of an action (^ replace, ~ delete, or an @ whole-request verb) decides what; the following @req.*/@rsp.* decides where; quotes hold the value.
"; curly quotes silently break a rule.Condition objects
| Object | Meaning | Example |
|---|---|---|
@req.host | Request host | @req.host CONTAINS "example.com" |
@req.api | Path | @req.api BEGINSWITH "/api/v1" |
@req.url | Full URL | @req.url MATCHES ".*\.jpg(\?.*)?$" |
@req.query | Query string | @req.query CONTAINS "debug=1" |
@req.method | HTTP method | @req.method == "POST" |
@req.port / @req.schema | Port / scheme | @req.schema == "http" |
@req.header["Name"] | Request header | @req.header["Content-Type"] CONTAINS "json" |
@req.bodyText | Request body | @req.bodyText CONTAINS "vip" |
@rsp.header["Name"] | Response header | @rsp.header["Content-Type"] CONTAINS "json" |
@rsp.bodyText | Response body | @rsp.bodyText CONTAINS "false" |
@rsp.status / @rsp.statusLine | Status code / line | @rsp.status == "404" |
Comparison & logic
Compare: == != > < >= <= CONTAINS BEGINSWITH ENDSWITH LIKE (wildcards */?) MATCHES (regex, whole match) IN ANY/ALL/NONE. Logic: && (AND) || (OR) ! (NOT), group with ().
Actions
| Action | Meaning | Example |
|---|---|---|
^ | Replace / insert | ^@req.header["X-Debug"] "1" |
~ | Delete | ~@req.header["Authorization"] |
@mock | Return a custom response | @mock "{\"ok\":true}" |
@reject* | Empty content (empty / image / object / array) | @reject-array |
@redirect | Redirect (or @301…@308) | @redirect 307 "https://test/x" |
@map-local | Serve a local file | @map-local "/shared/mock.json" |
@break | Break the request | @break |
ExampleAdd a debug header and flip a response field to true
Cond: @req.host CONTAINS "api.example.com" && @req.api BEGINSWITH "/feature" Act 1: ^@req.header["X-Debug"] "1" Act 2: ^@rsp.bodyText "\"enabled\":false" "\"enabled\":true"
FAQ
When does a rewrite rule take effect?
Save and enable the rule, ensure the global Rewrite gate is on, and send a new request to verify the result.
Can I rewrite traffic without learning the DSL?
Yes. Simple mode builds rules from conditions and intent cards, while expert mode keeps the DSL for advanced cases.
Can NetPeek return a mock response directly?
Yes. Mock Response can skip the upstream request and return custom content; Map Local can serve a file stored on the device.