简单Mock服务(moco)

下载地址:https://github.com/dreamhead/mocoarrow-up-right

简单使用 (Standalone Moco Runner)

Qucik Start 官方说明arrow-up-right Standalone Moco Runner Download(v 0.11.1)arrow-up-right

启动

java -jar moco-runner-<version>-standalone.jar http -p 12306 -s 22306 -c settings.json -p启动端口 -sshutdown端口,可以不指定,会默认分配。shutdown命令java -jar moco-runner-<version>-standalone.jar shutdown -s 9527 -c配置文件

配置

```json settings.json [ { "request": { "uri": "/json", "method" : "post" #如果不指定method则get、post均可以 }, "response": { "json": #json格式返回值 { "foo" : "bar" } } }, { "request": { "uri": "/text", "method" : "get" }, "response": { "text" : "bar" #text格式返回值 } } ]

### 匹配json请求参数

[JSON Request](https://github.com/dreamhead/moco/blob/master/moco-doc/apis.md#json-request)

#### 完全匹配json请求

```json
{
    "request": {
        "uri": "/json",
        "json": {
            "foo": "bar"
        }
    },
    "response": {
        "text": "foo"
    }
}

使用JSONPath来匹配是否包含指定的参数

示例: 当请求参数包含一个"$.biz.type"="lookback_bill"时,则返回数据

```json settings.json { "request": { "uri": "/activiti/thrid/calApi", "json_paths":{ "$.biz.type":"lookback_bill" } }, "response": { "json": { "code": 200, "message": "模拟计费成功" } } }

Last updated