NetPeek NetPeek

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.

  1. Swipe a row in Recent Requests → "New rewrite" (host/path prefilled), or tap + in the rewrite list.
  2. When it applies: pick "All requests" or add conditions (host contains / path begins with …).
  3. What to do: pick one of six intent cards.
  4. Set the details: fill fields per intent. A plain-language summary updates live; confirm and tap Save & Enable.
IntentUse
Edit HeaderAdd / change / delete a request or response header
Edit BodyReplace a piece of text in the response/request body
Mock responseSkip the real request and return custom content
Block requestReturn empty response / JSON / image — great for ad & tracker blocking
RedirectSend the request to another URL (e.g. prod → staging)
Local fileServe a file on the device as the response
New rewrite Open rewrite list
Multiple conditions are combined with AND. For OR, create another rule with the same action. For richer combos (multiple actions, parentheses, regex), tap Expert mode at the top-right of the editor.

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.

Always use straight ASCII quotes "; curly quotes silently break a rule.

Condition objects

ObjectMeaningExample
@req.hostRequest host@req.host CONTAINS "example.com"
@req.apiPath@req.api BEGINSWITH "/api/v1"
@req.urlFull URL@req.url MATCHES ".*\.jpg(\?.*)?$"
@req.queryQuery string@req.query CONTAINS "debug=1"
@req.methodHTTP method@req.method == "POST"
@req.port / @req.schemaPort / scheme@req.schema == "http"
@req.header["Name"]Request header@req.header["Content-Type"] CONTAINS "json"
@req.bodyTextRequest body@req.bodyText CONTAINS "vip"
@rsp.header["Name"]Response header@rsp.header["Content-Type"] CONTAINS "json"
@rsp.bodyTextResponse body@rsp.bodyText CONTAINS "false"
@rsp.status / @rsp.statusLineStatus 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

ActionMeaningExample
^Replace / insert^@req.header["X-Debug"] "1"
~Delete~@req.header["Authorization"]
@mockReturn a custom response@mock "{\"ok\":true}"
@reject*Empty content (empty / image / object / array)@reject-array
@redirectRedirect (or @301@308)@redirect 307 "https://test/x"
@map-localServe a local file@map-local "/shared/mock.json"
@breakBreak 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.

Related features