docs/en/docs/rules/resReplace.md
Replaces the response body content using a method similar to JavaScript's String.replace() (only valid for requests with a response body, such as 200 and 500). Supports multiple text formats:
application/json)application/xml)text/html)text/xxx)pattern resReplace://value [filters...]
| Parameters | Description | Detailed Documentation |
|---|---|---|
| pattern | Expression to match against the request URL | Match Pattern Documentation |
| value | Replacement configuration object, supported from the following sources: | |
| • Directory/file path | ||
| • Remote URL | ||
| • Inline/embedded/Values content | Operation Instruction Documentation | |
| filters | Optional filters, supporting matching: • Request URL/Method/Header/Content • Response Status Code/Header | Filter Documentation |
www.example.com/path file://(00user-11test-22user-33test) resReplace://user=abc&/\d+/g=number
Request https://www.example.com/path/to, browser receives:
numberabc-numbertest-numberabc-numbertest
``` resReplace.json
user: name
/\d+/g: num
```
# or (note the escape character)
``` resReplace.json
{
'user': 'name',
'/\\d+/g': 'num'
}
```
www.example.com/path file://(00user-11test-22user-33test) resReplace://{resReplace.json}
Request https://www.example.com/path/to Content received by the browser:
numname-numtest-numname-numtest
www.example.com/path1 resReplace:///User/xxx/test.json
www.example.com/path2 resReplace://https://www.xxx.com/xxx/params.json
# Editing a temporary file
www.example.com/path3 resReplace://temp/blank.json
Prepend To Body): resPrependPrepend HTML To Body, response type must be text/html): htmlPrependPrepend CSS To Body, response type must be text/html or text/css): cssPrependPrepend JS To Body, response type must be text/html, text/css, or application/javascript): jsPrependReplace Body): resBodyReplace Body, response type must be text/html): htmlBodyReplace Body, response type must be text/html or text/css): cssBodyReplace Body, response type must be text/html, text/css, or application/javascript): jsBodyAppend To Body): resAppendAppend HTML To Body, response type must be text/html): htmlAppendAppend CSS To Body, response type must be text/html or text/css): cssAppendAppend JS To Body, response type must be text/html, text/css, or application/javascript): jsAppendModify Body Text): resReplaceModify Form/JSON): resMergeDelete Form/JSON): delete://resBody.xxx