mockserver

(1)运行mockserver

docker pull mockserver/mockserver:latest

services:
  mockserver:
    image: mockserver/mockserver:latest
    ports:
      - "1081:1080"
    networks:
      - other
networks:
  other: {}

PS E:\docker\other> docker-compose up mockserver -d
[+] Running 1/1
 - Container other-mockserver-1  Started                                                                           2.5s
PS E:\docker\other>

(2)配置模拟请求与响应

请求地址
http://127.0.0.1:1081/mockserver/expectation
请求方式
PUT
请求体
{
	"httpRequest": {
		"method": "GET",
		"path": "/api/user"
	},
	"httpResponse": {
		"statusCode": 200,
		"body": {
			"id": 1,
			"name": "John Doe"
		},
		"headers": {
			"Content-Type": [
				"application/json"
			]
		}
	}
}
响应体
[
    {
        "httpRequest": {
            "method": "GET",
            "path": "/api/user"
        },
        "httpResponse": {
            "statusCode": 200,
            "headers": {
                "Content-Type": [
                    "application/json"
                ]
            },
            "body": {
                "id": 1,
                "name": "John Doe"
            }
        },
        "id": "fa55ccc3-60f5-4cd1-94c8-3e312add4319",
        "priority": 0,
        "timeToLive": {
            "unlimited": true
        },
        "times": {
            "unlimited": true
        }
    }
]

(3)测试

请求地址
http://127.0.0.1:1081/api/user
请求方式
GET
响应体
{
    "id": 1,
    "name": "John Doe"
}

(4)重置所有配置

请求地址
http://127.0.0.1:1081/mockserver/reset
请求方式
PUT
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值