您的位置:首页 > 其它

mock server 挡板服务搭建

2017-01-04 10:05 218 查看
官网:https://github.com/dreamhead/moco

启动moco服务

java -jar moco-runner-<version>-standalone.jar start -p 12306 -c foo.json

java -jar moco-runner-0.11.0-standalone.jar start -p 12306 -c foo.json

初始状态

{

    "response" :

      {

        "text" : "Hello, Moco"

      }

}
http://localhost:12306
 

带参数的 HTTP 请求

{

  "request" :

    {

      "uri" : "/foo",

      "queries" :

        {

          "param" : "blah"

        }

    },

  "response" :

    {

      "text" : "bar"

    }

}
http://localhost:12306/foo?param=blah
基于正则表达的 URL 匹配

{

  "request":

    {

      "uri":

        {

          "match": "/\\w*/foo"

        }

    },

  "response":

    {

      "text": "bar"

    }

}

在地址栏输入多个地址(/foo 前带有任意字符, 比如 http://localhost:12306/xxx/foo)
跳转

{

  "request" :

    {

      "uri" : "/redirect"

    },

  "redirectTo" : "http://www.baidu.com"

}
http://localhost:12306/redirect
返回 JSON 对象

{

    "request": {

        "uri": "/json"

    },

    "response": {

        "json": {

            "foo" : "bar"

        }

    }

}
http://localhost:12306/json
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  moco mockserver