1.单个json文件
(1)目录配置
(2)新建foo.json
在project文件夹中新建foo.json
[ { "request" : { "uri" : "/foo" }, "response" : { "text" : "foo" } } ]
(3)执行&访问
windows在命令行cmd中:java -jar moco-runner-0.10.2-standalone.jar start -p 12306 -c project/foo.json浏览器中访问:http://localhost:12306/foo
2.Golbal-Settings
We could put all configurations in one single configuration files. But if we want stub many services in a single Moco instance, the configurations file would be huge. In this case, we can use settings file to separate our configurations for different into different configugration files.意思是,当一个moco实例要对外提供非常多的json文件时候,可以用include将所有json文件统一注册
(1)准备json文件
bar.json[ { "request" : { "uri" : "/foo" }, "response" : { "text" : "foo" } } ]
main.json[ { "include" : "project/foo.json" }, { "include" : "project/bar.json" } ]注意文件的路径,否则会抛找不到文件
(2)执行&访问
windows在命令行cmd中:java -jar moco-runner-0.10.2-standalone.jar start -p 12306 -g project/main.json浏览器中访问:http://localhost:12306/foo
http://localhost:12306/bar
3.Context
context.json[ { "context": "/foo", "include": "project/foo.json" }, { "context": "/bar", "include": "project/bar.json" } ]
windows在命令行cmd中:java -jar moco-runner-0.10.2-standalone.jar start -p 12306 -g project/context.json浏览器中访问:http://localhost:12306/foo/foo
http://localhost:12306/bar/bar
时间: 2024-11-05 05:50:01