模拟 – API 创建和测试工具:示例
Mock – An API creation and testing utility: Examples

原始链接: https://dhuan.github.io/mock/latest/examples.html

使现有的API变慢可以很容易地通过组合mock的Base APIs和delay选项来实现。$ mock serve -p 8000 --base example.com --delay 2000 然而,你可能只想让特定的端点变慢,而不是整个API。这可以使用中间件来实现:$ mock serve -p 8000 --base example.com --middleware ' if [ "${MOCK_REQUEST_ENDPOINT}" = "some/endpoint" ] then sleep 2 # 等待两秒 fi ' 通过最后一个例子,我们的API在localhost:8000会充当example.com的代理。所有请求都会立即得到响应,除了some/endpoint,它将有2秒的延迟。

相关文章

原文

Making an existing API slow can be easily accomplished combining mock’s Base APIs and the delay option.

$ mock serve -p 8000 --base example.com --delay 2000

You may want however to make a specific endpoint slow instead of the whole API. This can be achieved using middlewares:

$ mock serve -p 8000 --base example.com --middleware '
if [ "${MOCK_REQUEST_ENDPOINT}" = "some/endpoint" ]
then
    sleep 2 # wait two seconds
fi
'

With that last example, our API at localhost:8000 will act as a proxy to example.com. All requests will be responded immediately except some/endpoint which will have a delay of 2 seconds.

联系我们 contact @ memedata.com