file
Use a local file to respond to requests. Suitable for:
- Setting up a local development environment
- Debugging local front-end pages
- Interface mock scenarios
Rule Syntax
txt
pattern file://value [filters...]| Parameters | Description | Detailed Documentation |
|---|---|---|
| pattern | Expression to match the request URL | Match Pattern Documentation |
| value | Operation content. Supports the following types: • Directory/File Path • Remote URL • Inline/Embedded/Values Content | Operation Instruction Documentation |
| filters | Optional filters. Supports matching: • Request URL/Method/Header/Content • Response Status Code/Header | Filter Documentation |
Replace a Local File
txt
# Basic Usage
www.example.com/path file:///User/xxx/test
# Windows path
www.example.com/path file://D:\test
# Exclude specific interfaces
www.example.com/path file:///User/xxx/test excludeFilter://*/path/cgi
# Match based on request content
www.example.com/path file:///User/xxx/test includeFilter://b:/"cmdname":\s*"test"/iFeature Description:
- Automatic path concatenation: Accessing
https://www.example.com/path/x/y/zwill map to/User/xxx/test/x/y/z - Disable path concatenation: Use
< >to wrap the pathtxtwww.example.com/path file://</User/xxx/test>Accessing
https://www.example.com/path/x/y/zwill only automatically load the file corresponding to/User/xxx/test
Quick Replacement
If working with local files is inconvenient, you can also use Whistle's Inline/Embedded/Values functionality to set the response content through the interface:
txt
# Inline values cannot contain spaces
www.example.com/path file://({"ec":0})
# Embedded values (spaces and line breaks are allowed)
``` test.json
{
"ec": 2,
"em": "error"
}
```
www.example.com/path file://{test.json}
test.jsonIf the content is large, place it in Values.
Replacing a Temporary File
If the content is large and working with local files is inconvenient, you can use Whistle's temporary file functionality:
txt
www.example.com/path file://temp/blank.htmlSteps:
- Hold down
Command (Mac)/Ctrl (Win) - Click in the rule
file://temp/blank.html - Enter the response content in the pop-up editor.
Mock JSONP
txt
www.example.com/path file://`(${query.callback}({"ec":0}))` # Inline values cannot contain spaces
# Inline values (spaces and newlines are allowed)
``` test.json
${query.callback}({
"ec": 2,
"em": "error"
})
```
www.example.com/path file://`{test.json}`Template strings do not work directly in the following scenarios:
- When referencing a local file path
- When referencing a remote URL
When encountering the above limitations, you can use the tpl function as an alternative.
Advanced Usage
Multi-Directory Search:
txt
www.example.com/path file:///path1|/path2|/path3Search Logic:
- Check in order: /path1/x/y/z → /path2/x/y/z → /path3/x/y/z
- Return immediately if the first existing file is found
- Return
404if all files are not found