ApiPatcher is a powerful Chrome extension designed for developers to intercept and modify HTTP requests and responses on the fly.
- Modify Request Headers: Add or overwrite headers (e.g.,
Origin,Referer,Authorization) for specific URLs. - Modify Request Body: Inject custom JSON payloads into
POST/PUTrequests. - Modify Response Body: Mock server responses by replacing the returned JSON data with your own.
- Modify Response Headers: Overwrite response headers (e.g.,
Access-Control-Allow-Origin) to fix CORS issues during development. - Zero Config: Works immediately with a simple UI.
- Regex Support: Target URLs using substring matching (regex support coming soon).
- Clone this repository or download the source code.
- Open Chrome and navigate to
chrome://extensions. - Enable Developer mode in the top right corner.
- Click Load unpacked and select the project directory.
- Click the ApiPatcher icon in the toolbar.
- Manage Rules:
- You will see a list of your configured rules.
- Click + New Rule to create a new interception rule.
- Use the toggle switch in the list to quickly Enable/Disable a rule.
- Configure a Rule:
- Target URL: Enter a substring of the URL you want to patch (e.g.,
api/v1/user). - Request Headers: Add custom headers to inject.
- Request Body: Set a JSON payload to override the request body.
- Response Body: Set a JSON payload to mock the server response.
- Response Headers: Add response headers (e.g., to fix CORS).
- Click Save Rule to apply changes.
- Target URL: Enter a substring of the URL you want to patch (e.g.,
- Apply Changes:
- Changes are saved immediately. Refresh your target page to see them in effect.
ApiPatcher 是一款专为开发者设计的 Chrome 插件,用于实时拦截和修改 HTTP 请求与响应。
- 多规则支持: 同时管理多个不同的拦截规则,独立配置。
- 修改请求头 (Request Headers): 为特定 URL 添加或覆盖请求头(如
Origin,Referer,Authorization)。 - 修改请求体 (Request Body): 向
POST/PUT请求中注入自定义的 JSON 数据。 - 修改响应体 (Response Body): 通过替换返回的 JSON 数据来 Mock 服务器响应。
- 修改响应头 (Response Headers): 覆盖响应头(如
Access-Control-Allow-Origin),轻松解决开发时的 CORS 跨域问题。 - 快速开关: 在规则列表中直接启用或禁用特定规则。
- 零配置: 界面简单,即装即用。
- 克隆本仓库或下载源代码。
- 打开 Chrome 浏览器,访问
chrome://extensions。 - 打开右上角的 开发者模式 (Developer mode)。
- 点击 加载已解压的扩展程序 (Load unpacked),选择本项目文件夹。
- 点击浏览器工具栏上的 ApiPatcher 图标。
- 管理规则:
- 你会看到所有已配置规则的列表。
- 点击 + New Rule 创建新规则。
- 使用列表中的开关快速 启用/禁用 规则。
- 配置规则:
- Target URL: 输入你想拦截的 URL 片段(例如
api/v1/user)。 - Request Headers: 添加自定义请求头。
- Request Body: 设置要覆盖的请求体数据。
- Response Body: 设置要 Mock 的响应体数据。
- Response Headers: 添加响应头(如解决跨域问题)。
- 点击 Save Rule 保存。
- Target URL: 输入你想拦截的 URL 片段(例如
- 应用更改:
- 保存后立即生效。刷新目标页面即可看到效果。