xhr-mocker
Version:
a npm module to mock/modify xhr/fetch responses for front-end development
49 lines (41 loc) • 1.57 kB
Markdown
A powerful tool for intercepting and modifying Ajax/Fetch request responses.
**Core Features:**
- [x] Intercept and modify AJAX/Fetch request responses
- [x] Real-time request monitoring and visualization
- [x] Support immediate response mode without waiting for actual requests
- [x] Dynamic loading in development environment without affecting production code
```
npm i xhr-mocker@latest
```
```javascript
// Entry file
import { mockInit } from 'xhr-mocker'
// Initialize at application entry
// React projects
mockInit({
rules:[], // Domain rules to intercept (supports regex), typically just configure main project domain
excludeRules:[] , // Domain rules to exclude (supports regex), includes built-in exclusions
mockPanelSdkUrl: '' // Mock panel SDK URL,default is 'https://unpkg.com/xhr-mocker-panel-sdk@latest/dist/mock-panel-sdk.umd.js'
disabled: false // Whether to disable。If true, the mock-tool will not be loaded
})}
// Vue projects
mockInit({
rules: []
}).then(() => {
new Vue({
render: h => h(App)
}).$mount('#app')
})
```
1. Open control panel - monitor all requests after enabling listening
2. Toggle Mock functionality using the switch button
3. Configure immediate response mode for individual endpoints
In the response editor, you can:
1. Freely edit response data
2. Extend functionality based on panel-sdk。eg: Auto-generate mock data from API documentation or generate simulated data using AI
MIT License.