从 http-responses 模拟

从包含原始 HTTP 响应的文件为 MockResponsePlugin 创建模拟文件。

概要

devproxy mocks from-http-responses <http-response-files>... [options]

Arguments:
  <http-response-files>  Glob pattern to the file(s) containing HTTP responses to create mock responses from

Options:
  --mocks-file <mocks file>  File to save the generated mock responses to (required)
  --log-level <level>        Logging level: trace|debug|information|warning|error
  -h, --help                 Show help

Usage

devproxy mocks from-http-responses <http-response-files> --mocks-file <mocks-file>

Arguments

Name Description Required Default
<http-response-files> 包含 HTTP 响应的文件的一个或多个 glob 模式,用于从中创建模拟响应,例如 *.http。 开发代理解析相对于当前文件夹的模式。 是 None

选项

Name Description 允许的值 Default
--mocks-file <mocks file> 要保存生成的模拟响应的文件。 Required. None
--log-level <loglevel> 要记录的消息级别 trace、debug、information、warning、error information

退出代码

Code Meaning
0 成功
1 没有与指定模式匹配的文件,或者开发代理无法分析一个或多个 HTTP 响应文件
2 输入或用法无效

当开发代理无法分析某些文件时,它仍会为成功分析的文件编写模拟,并退出该文件 1。

注解

只有在 mocks 开发代理配置文件中启用 MockResponsePlugin 时,该命令才可用。

每个文件必须包含以状态行开头的单个原始 HTTP 响应,例如:

HTTP/1.1 200 OK
Content-Type: application/json

{
  "id": 1,
  "name": "Contoso"
}

对于每个文件,开发代理都会创建一个模拟,其中包含响应的状态代码、标头和正文。 如果响应具有 application/json 内容类型,Dev Proxy 会将正文存储为 JSON。 否则,它将正文存储为字符串。 每个生成的模拟将请求匹配到任何 URL(*),因此请更新 request 每个模拟的属性以匹配要模拟的请求。