当前位置:网站首页>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 :
边栏推荐
- Principle and implementation of UDP penetration NAT in P2P
- 【硬件工程师】DC-DC隔离式开关电源模块为什么会用到变压器?
- Hcip first day experiment
- H5测试点(思维导图)
- EDI 对接CommerceHub OrderStream
- Go language context control function execution timeout return
- An article about ultrasonic humidifier
- [untitled]
- Is it safe to open a futures account online? How to apply for a low handling fee?
- How to rectify the unqualified EMC of electronic products?
猜你喜欢

How to fix the first row title when scrolling down in Excel table / WPS table?

I'm also drunk. Eureka delayed registration and this pit!

【解决方案】Microsoft Edge 浏览器 出现“无法访问该页面”问题

Dating activity records

吴恩达机器学习编程作业无法暂停pause问题解决

Ultimate doll 2.0 | cloud native delivery package

Redistemplate solves the problem of oversold inventory in the seckill system with high speed - redis transaction + optimistic lock mechanism

四六级

WPF 实现用户头像选择器

Excel表格 / WPS表格中怎么在下拉滚动时让第一行标题固定住?
随机推荐
Nineteen year old summary
Interviewer: talk about log The difference between fatal and panic
函数名指针和函数指针
食品安全 | 八问八答带你重新认识小龙虾!这样吃才对!
Ultimate doll 2.0 | cloud native delivery package
PageHelper can also be combined with lambda expressions to achieve concise paging encapsulation
世界各地的标志性建筑物
Redis source code and design analysis -- 15. RDB persistence mechanism
简述Synchronized以及锁升级
如何看一本书
UFT(QTP)-总结点与自动化测试框架
2022/7/23
排序还需要了解的信息以及链表
Automated test Po design model
With 8 years of product experience, I have summarized these practical experience of continuous and efficient research and development
Notes on Flickr's dataset
EDI docking commercehub orderstream
New and malloc
【Cadence Allegro PCB设计】error: Possible pin type conflict GND/VCC Power Connected to Output
[Hardware Engineer] can't select components?