日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

Mock Server

發布時間:2025/7/25 49 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Mock Server 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

下載地址:https://repo1.maven.org/maven2/com/github/dreamhead/moco-runner/

此處使用standalone的方式,不使用api用法

啟動方式(單獨配置文件啟動):java -jar (jar包位置) (協議) -p (端口) -c 配置文件地址

1 全局配置文件

[{"context":"/path1", "include":"startup.json"},{"context":"/path2", "include":"startup2.json"} ]

這兒的啟動方式有變化,?啟動方式(全局配置文件啟動):java -jar (jar包位置) (協議) -p (端口) -g 配置文件地址,訪問要加上context的utl,如訪問startup1.json中的訪問方法,

訪問路徑為:http://localhost:8888/path1/demo/noparam

以下是一些常見的方法

config.json

[{"context":"/path1", "include":"startup.json"},{"context":"/path2", "include":"startup2.json"} ]

startup.json

[{"description": "這是一個get請求","request": {"uri": "/demo","method": "get","queries": {"name": "lww","age": "34"}},"response": {"text": "返回的方式為文本","headers":{"Content-Type":"text/html;charset=gbk"}}},{"description": "這是一個不帶有請求參數的get請求","request": {"uri": "/demo/noparam","method": "get"},"response": {"text": "這是不帶有請求參數的get請求","headers": {"Content-Type":"text/html;charset=gbk"}}},{"description": "這是一個post的請求","request": {"uri": "/demo/postNoParam","method": "post"},"response": {"text": "這是一個post請求,不帶有參數","headers": {"Content-Type":"text/html;charset=gbk"}}},{"description": "這是一個帶有的參數的post請求","request": {"uri": "/demo/postwithparam","method": "post","forms": {"name": "lww","age": "45"}},"response": {"text": "這是一個post請求,并且帶有參數","headers": {"Content-Type":"text/html;charset=gbk"}}},{"description": "這是一個get請求,帶有cookie信息","request": {"uri": "/demo/withCookie","method": "get","cookies": {"hello": "lww"}},"response": {"headers": {"Content-Type":"text/html;charset=gbk"},"text": "這是一個帶有cookie信息的get請求"}},{"description": "這是一個帶有cookie信息的post請求","request": {"uri": "/demo/postwithcokie","method": "post","cookies": {"hello": "lww"},"json": {"name": "lww","age": "45"}},"response": {"text": "這是一個帶有cookie信息的post請求","headers": {"Content-Type":"text/html;charset=gbk"}}},{"description": "這是一個帶有返回狀態碼的請求","request": {"method": "get","uri": "/demo/withstatus"},"response": {"json": {"lww": "33333","age": "45"},"status": "200","headers": {"Content-Type":"text/html;charset=gbk"}}},{"description": "帶有headers信息的請求,post與get一致","request": {"uri": "/demo/withheaders","method": "get","headers": {"content-type": "application/json"}},"response": {"text": "帶有headers的請求"}},{"description": "重定向","request": {"uri": "/demo/cdx"},"redirectTo": "/demo/tocdx"},{"description": "重定向到這個","request": {"uri": "/demo/tocdx"},"response": {"text": "到這兒","headers": {"Content-Type":"text/html;charset=gbk"}}},{"description": "上傳文件","request": {"uri": "/demo/file"},"response":{"file": "C:\\Users\\lwf\\Desktop\\test-output\\report.html"}}]

  startup2.json

[{"description": "這是delete請求","request": {"method": "delete","uri": "/demo/del"},"response": {"status": "200"}},{"description": "這是一個put方法","request": {"uri": "/demo/put","method": "put"},"response": {"status": "200"}},{"description": "xml","request": {"uri": "/demo/xml","text": {"xml": "<request><parameters><id>1</id></parameters></request>"}},"response": {"status": "200"}} ]

更多查看:https://github.com/dreamhead/moco/blob/master/moco-doc/apis.md

以上是我暫時能想到的常用的請求

網上看教程moco是支持熱部署的, 但是不知道是因為我下載的版本太低還是怎么回事并不能進行熱部署

轉載于:https://www.cnblogs.com/sailfan/p/10427939.html

《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀

總結

以上是生活随笔為你收集整理的Mock Server的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。