moco设置URI请求参数

背景

今天使用dreamhead的moco做一个源站mock时,发现不能直接在request的uri中直接指定传参,如下/foo?domain=baidu.com,访问http://ip:port/foo?domain=baidu.com,返回400

{
  "request" :
    {
      "uri" : "/foo?domain=baidu.com"
    },
  "response" :
    {
      "text" : "bar"
    }
}

解决方案

将参数独立放到queries下,与uri同级,配置如下:

{
  "request" :
    {
      "uri" : "/foo",
      "queries":{"domain":"baidu.com"}
    },
  "response" :
    {
      "text" : "bar"
    }
}

访问http://ip:port/foo?domain=baidu.com,返回bar,完成。
记录一下踩的坑,参考:https://github.com/dreamhead/moco/blob/master/moco-doc/apis.md

你可能感兴趣的:(moco设置URI请求参数)