mocks from-http-responses

從包含原始 HTTP 回應的檔案中建立一個 mocks 檔案,用於 MockResponsePlugin 。

Synopsis

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 預設
<http-response-files> 對包含 HTTP 回應的檔案施加一個或多個 glob 模式,以產生例如從 *.http的模擬回應。 Dev Proxy 會根據目前資料夾解析這些模式。 Yes None

選項

Name Description 允許的值 預設
--mocks-file <mocks file> 儲存產生的模擬回應的檔案。 Required. None
--log-level <loglevel> 要記錄的訊息層級 trace、、 debug、 information、 warning、 error information

出口代碼

Code Meaning
0 Success
1 沒有任何檔案符合指定的模式,或者開發代理無法解析一個或多個 HTTP 回應檔案
2 輸入或使用無效

當 Dev Proxy 無法解析部分檔案時,它仍會為成功解析的檔案寫入模擬檔案,並以 1.( )

備註

這個 mocks 指令只有在你啟用 Dev Proxy 設定檔中的 MockResponsePlugin 時才可用。

每個檔案必須包含一個以狀態行開頭的原始 HTTP 回應,例如:

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

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

對於每個檔案,Dev Proxy 會建立一個包含回應狀態碼、標頭和正文的模擬檔案。 如果回應有內容類型, application/json Dev Proxy 會將主體存成 JSON。 否則,它會將身體儲存成一條繩子。 每個產生的 mock 都會將請求匹配到任意 URL(*),因此 request 更新每個 mock 的屬性,使其符合你想要模擬的請求。