Mock基础知识

使用的框架:moco框架
下载地址:https://repo1.maven.org/maven2/com/github/dreamhead/moco-runner/1.1.0/

启动方式:
java -jar ./moco-runner-1.1.0-standalone.jar http -p 8899 -c json文件
注意:mocorunner是热部署,服务不用重启,即可完成升级操作


mock接口
字段值
字段含义
子字段值
子字段含义


description
描述

 

request
请求代码块
uri
请求地址

 


method
请求方法

 


queries
get方法请求参数时用

 


forms
post方法请求参数时用

 


redirectTo
重定向到哪一个uri中

 


cookies

cookies信息
key
cookie名称


value
cookie值


headers
请求头


response
返回代码块

 

 

Get请求
[
{
"description": "无参get请求",
"request":{
"uri": "/getNoParams",
"method": "get"
},
"response":{
"text": "无参数get请求成功"
}
},

{
"description": "有参get请求",
"request":{
"uri": "/getWithParams",
"method": "get",
"queries": {
"name": "zhangsan",
"age": "18"
}
},
"response":{
"text": "有参数get请求成功"
}
},

{
"description": "有参get请求返回json",
"request":{
"uri": "/getWithParams2",
"method": "get",
"queries": {
"name": "lisi",
"age": "17"
}
},
"response":{
"status": "200",
"json":{
"msg": "success",
"status": "10000"
}
}
},

{
"description": "有参get请求json",
"request":{
"uri": "/getWithParams3",
"method": "get",
"json": {
"name": "wangwu",
"age": 16
}
},
"response":{
"status": "200",
"json":{
"msg": "success",
"status": "10000"
}
}
}
]
Post请求
[
{
"description": "无参数post请求",
"request": {
"uri": "/postNoparams",
"method": "post"

},
"response": {
"text": "无参post请求"
}
},

{
"description": "有参数post请求",
"request": {
"uri": "/postWithparams",
"method": "post",
"forms": {
"name": "zhangsan",
"age": "18"
}
},
"response": {
"text": "有参数post请求"
}
},
{
"description": "有参数post请求",
"request": {
"uri": "/postWithparams2",
"method": "post",
"json": {
"name": "zhangsan",
"age": 18
}
},
"response": {
"status": "200",
"json":{
"msg": "success",
"status": "10000"
}
}
},

{
"description": "携带cookies的请求",
"request": {
"uri": "/postwithCookies",
"method": "post",
"forms": {
"name": "lisi",
"age": "17"
},
"cookies": {
"session": "true"
}
},
"response": {
"text": "携带cookies的请求"
}
},

{
"description": "携带header的请求",
"request": {
"uri": "/postwithHeader",
"method": "post",
"forms": {
"name": "lisi",
"age": "17"
},
"headers": {
"session": "true",
"Content-Type":"application/json"
}
},
"response": {
"text": "携带header的请求"
}
}
]

posted @   王广福  阅读(71)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 一文读懂知识蒸馏
· 终于写完轮子一部分:tcp代理 了,记录一下
点击右上角即可分享
微信分享提示