前言
上一篇搭建好了moco环境,本篇为moco中request和response的具体使用
moco使用(request部分)
1)description字段,在所有JSONAPI中,可以使用description来描述这个会话的目的。它只是用作注释,在运行时将被忽略。
//test.json
[
{
"description": "any response",
"response": {
"text": "foo"
}
}
]
2)request字段,根据请求进行响应
//test.json
[
{
"request" :
{
"text" : "foo"
},
"response" :
{
"text" : "bar"
}
}
]
3)request-uri字段,根据不同url响应不同信息
//test.json
[
{
"request" :
{
"uri" : "/foo"
},
"response" :
{
"text" : "bar"
}
}
]
浏览器输入:localhost:12306/foo,会返回“bar”
4)request-queries字段,请求带参数
//test.json
[
{
"request" :
{
"uri" : "/foo",
"queries" :
{
"param" : "blah"
}
},
"response" :
{
"text" : "bar"
}
}
]
浏览器输入:localhost:12306/foo?param=blah,会返回“bar”
5)request-method字段,请求方法(以get为例,其他方法与其操作一致)
//test.json
[
{
"request" :
{
"method": "get",
"uri" : "/foo"
},
"response" :
{
"text" : "bar"
}
}
]
6)request-headers字段,设置请求头信息
//