当前位置:网站首页>Mock service Moco series (I) - introduction, first demo, get request, post request
Mock service Moco series (I) - introduction, first demo, get request, post request
2022-07-25 17:50:00 【wangmcn】
Mock service moco series ( One )
brief introduction 、 first Demo、Get request 、Post request
Catalog
- 1、 brief introduction
- 2、 download
- 3、 first Demo
- 3.1、 The configuration file
- 3.2、 start-up moco
- 3.3、 visit moco
- 4、Get request
- 5、Post request
1、 brief introduction
1、 What is? mock?
mock Translation means simulation .
2、 What is? moco?
moco It's a simple one Stub frame .Stub Can be translated into pile , Refers to the program segment used to replace some functions . Pile program can be used to simulate the behavior of existing programs ( For example, the process of a remote machine ) Or a temporary replacement for the code to be developed . Simply speaking ,moco It solves the problem that there is no back-end support when developing the front-end , When developing interfaces, it depends on embarrassing scenarios that are not in place .
The main features :
(1) Just a simple configuration request、response And so on , Support http、https、socket etc. .
(2) Support in request Set in headers、cookies etc. .
(3) Yes GET、POST、PUT、DELETE And so on , It's perfect for web Development .
(4) No environment configuration required , Yes Java Just the environment .
(5) After modifying the configuration , Take effect immediately . Just maintain the interface , That is to say, the contract is enough .
(6) Supports all possible data formats , Such as json、text、xml、file etc. .
Official website :
https://github.com/dreamhead/moco
2、 download
Official download address :
https://repo1.maven.org/maven2/com/github/dreamhead/moco-runner/
Download the corresponding version , Use of this article 0.12.0 edition , download moco-runner-0.12.0-standalone.jar file .
3、 first Demo
3.1、 The configuration file
moco The configuration file format must be json Format . The configuration file is an array , in other words , You can configure the requests and responses of multiple interfaces in one file .
1、 Profile common fields :
description: Used to describe the purpose of this conversation , It is only used as a comment , Will be ignored at runtime .
request: Request content .
response: Response content .
uri: Request concerns .
method: Based on specified HTTP Method (get、post、put、delete、HEAD).
queries:get Request parameters .
forms:post Request parameters .
text: Text .
json:Json Format .
file: file .
headers: Message header .
cookies:cookie Information .
status: Response status code .
redirectTo: Redirect the request to the specified url On .
match: Regular expressions .
latency: Delay .
template: Templates .2、 Create a Demo Example (01Demo.json).
description Describe this interface .
The request is filled in request in , The response content is filled in response in .
The response content format is text Text format .
The request address format is :IP+ Port number +uri Splicing into ( for example http://10.106.29.102:8083/demo)
The contents are as follows :
[
{
"description":"Moco Demo",
"request":{
"uri":"/demo"
},
"response":{
"text":"Hello Moco"
}
}
]3.2、 start-up moco
The command line enters the download completed moco-runner-0.12.0-standalone.jar The package directory .
Input start moco The service command :
java -jar moco-runner-0.12.0-standalone.jar http -p 8083 -c < Profile path >/XXX.json
notes :
-p Appoint moco Service port
-c Configuration file path and file name for example :
java -jar moco-runner-0.12.0-standalone.jar http -p 8083 -c 01Demo.json
As shown in the figure :moco Service startup , The port number is 8083.
3.3、 visit moco
1、 Open browser access moco Service address .
(1) Local access :
http://localhost:8083/demo
perhaps :
http://127.0.0.1:8083/demo
(2) The remote access (IP by 10.106.29.102):
http://10.106.29.102:8083/demo
2、 The access results show .
3、 Console display moco Service request and response information .
4、Get request
1、 establish 02Get.json The configuration file .
The configuration file has 2 Interface ( Without parameters Get request 、 Parametric Get request ).
"method":"get" by Get request , If you do not add this field , The interface defaults to Get request .
queries by Get Request parameters ( add to 2 Parameters username、password Its corresponding value ).
The contents are as follows :
[
{
"description":"Get request ( No parameters )",
"request":{
"uri":"/getdemo",
"method":"get"
},
"response":{
"text":"Moco Get"
}
},
{
"description":"Get request ( With parameters )",
"request":{
"uri":"/getdemo2",
"method":"get",
"queries":{
"username":"admin",
"password":"123456"
}
},
"response":{
"text":"admin,123456"
}
}
]2、 Input start moco The service command .
java -jar moco-runner-0.12.0-standalone.jar http -p 8083 -c 02Get.json
3、 Browser access moco Service address .
(1)Get request ( No parameters )
Access address :
http://localhost:8083/getdemo
The access results show :
(2)Get request ( With parameters )
Access address :
http://localhost:8083/getdemo2?username=admin&password=123456
The access results show :
5、Post request
1、 establish 03Post.json The configuration file .
The configuration file has 2 Interface ( Without parameters Post request 、 Parametric Post request ).
"method":"post" by Post request .
forms by Post Request parameters ( add to 2 Parameters username、password Its corresponding value ).
The contents are as follows :
[
{
"description":"Post request ( No parameters )",
"request":{
"uri":"/postdemo",
"method":"post"
},
"response":{
"text":"Moco Post"
}
},
{
"description":"Post request ( With parameters )",
"request":{
"uri":"/postdemo2",
"method":"post",
"forms":{
"username":"admin",
"password":"123456"
}
},
"response":{
"text":"admin,123456"
}
}
]2、 Input start moco The service command .
java -jar moco-runner-0.12.0-standalone.jar http -p 8083 -c 03Post.json
3、Postman visit moco Service address .
Open the installed Postman.
(1)Post request ( No parameters )
The agreement type is selected as POST
Access address :http://localhost:8083/postdemo
Click on Send, The access results show :
(2)Post request ( With parameters )
The agreement type is selected as POST
Access address :http://localhost:8083/postdemo2
Body Add parameter ( Parameter name and parameter value ).
Click on Send, The access results show :
边栏推荐
- Interviewer: talk about log The difference between fatal and panic
- 食品安全 | 八问八答带你重新认识小龙虾!这样吃才对!
- Several implementations of PHP to solve concurrency problems
- Postman快速上手
- Resttemplate realizes the unified encapsulation (printable log) of post, put, delete, get, set request and file upload (batch files and parameters) through generics
- Nineteen year old summary
- 交叉验证(cv)学习笔记
- Interface automation test postman+newman+jenkins
- Principle and implementation of UDP penetration NAT in P2P
- 吴恩达机器学习编程作业无法暂停pause问题解决
猜你喜欢

Three dimensional function display of gray image
![[solution] the Microsoft edge browser has the problem of](/img/47/7e20a4f1e04577153e7cf0a6c61f26.png)
[solution] the Microsoft edge browser has the problem of "unable to access this page"

Idea 必备插件

Lwip之内存与包缓冲管理

Interviewer: talk about log The difference between fatal and panic

Food safety | eight questions and eight answers take you to know crayfish again! This is the right way to eat!

11、照相机与透镜

2022/7/23

Thesis reading_ Multi task learning_ MMoE

什么是 IP SSL 证书,如何申请?
随机推荐
绘制pdf表格 (二) 通过itext实现在pdf中绘制excel表格样式设置中文字体、水印、logo、页眉、页码
[solution] the Microsoft edge browser has the problem of "unable to access this page"
【解决方案】Microsoft Edge 浏览器 出现“无法访问该页面”问题
Idea essential plug-ins
STM32 PAJ7620U2手势识别模块(IIC通信)程序源码详解
mysql case when
Highlights
stm32F407------SPI
简述Synchronized以及锁升级
EDI 对接CommerceHub OrderStream
Brief introduction of bubble sort and quick sort
Cet
走马卒
Nineteen year old summary
NPDP多少分通过?如何高分通过?
ROS learning notes (IV) ROS cannot solve rosdep init or update
计算日期或日期格式化
世界各地的标志性建筑物
Crawler framework crawler
Summary of knowledge points for final review of server-side architecture design