Analog interface testing and required third-party calls, find a lot of mock tools, found moco on git, learning about it, share it.
First, download Moco, Moco address
After downloading, it is a jar package.
Second, the configuration profile moco
(1) create a file in the same directory config.json jar package:
(2) Configuration config.json (here mainly configured configuration request value of the analog interface to a third party, the return value, request class):
Common configuration (note that you want to delete one of the Chinese comments):
(1)
{ "Request" : { "Method": "POST" , # simulation request method "URI": "/ jiekou" , the interface name # simulation request "text" : { "JSON": "{\" ID \ ": \ "12306 \", \ " name \": " body # appointment request is for json format and text content is {" \ "Moco \"} ID ":" 12306 "," name ":" Moco " } (Note that to escape the double quotes) "headers" : { "Content-type": "file application / JSON" # appointment request header } }, "Response" : { "Status": "200 " , the state returns to # 200 " text ":" ceshi " # returns to the text ceshi } }
(2)
{ "request": { "headers":{"Content-Type":"application/json;charset=UTF-8"}, #约定请求头 "method":"post",#约定请求方法 "uri":"/jiekou2",#约定请求接口名 "text": { "json":"{\"type\":\"1\",\"data\":{\"citeCaseId\": \"11111111\",\"party\": [{\"partyId\": \"001\",\"name\": \"张三\",\"agent\":[{\"agentId\": \"002\"},{\"agentId\": \"002\"}]}]}}"lack the necessary parameters."necessary parameter is missing."} # Convention Return value as JSON, and the content of { "code": 101, ""json": { "code", # agreed to return to the state "Status": "200 is" {:"Response" }, }# Appointment request JSON } } }
(3)
{ "request": { "headers":{"Content-Type":"application/json"}, #请求头 "method":"post", #请求方法 "uri":"/getList",#请求接口名 "text": { "json":"{\"sasj\":\"20100101\",\"tbsj\":\"20100101\",\"fywid\":\"88888\",\"Token\":\"1\",\"Pagenumber\":\"1\"}" #请求正文 } }, "response": { "file":"ceshi.xml" } }# Request returns a file (content can be returned in xml, the package will be placed under same directory jar can)
NOTE: To simulate simultaneously a plurality of interfaces, it can be included in [], and by dividing, i.e. json format.
Third, start mock:
Enter cmd in the search field and press enter:
java -jar moco-runner-0.12.0-standalone.jar http -p 8881 -c config.json
Run successfully. Use postman or other direct interfaces to call the Tool Calling Interface.