https://github.com/six-ddc/mirage
一个基于 DSL 的快速构建简单的 HTTP Server 的命令行工具
DSL 描述基于 Groovy 语法实现,HTTP Server 基于 Spring Boot 框架,使用简单且性能优秀
方便灵活的 Mock 数据(支持 Data Faker)
零配置,下载 release 包即可直接运行(只依赖 Java 运行时环境)
构建静态文件服务(参考下面示例)
前后端分离,接口设计,开发阶段接口对接时,快速编写 HTTP 测试用例,支持定时更新 DSL 描述文件或目录
mirage -c 'get("/hello") { resp.println "world!"}'
# curl http://127.0.0.1:8080/hello
# world!
mirage -c 'get("/files/**") { resp.index "." }'
# curl http://127.0.0.1:8080/files/pom.xml
user.mir
并输入handle path: '/user/{uid}/get', method: "GET", {
sleep 100.millisecond
resp.json {
id req.pathVariables.uid
name random.forRegex(/[A-Z][a-z]{3,10}/)
t new Date()
data {
contact 1..2, {
id it
name faker.name().name()
address faker.address().fullAddress()
phone faker.phoneNumber().cellPhone()
}
}
}
}
get('/user/{uid}/get2') {
// 或者基于模板语法直接编写 JSON response
resp.eval """{
"id": "${req.pathVariables.uid}",
"name": "${random.forRegex(/[A-Z][a-z]{3,10}/)}",
"t": "${new Date()}",
"data": {
"contact": [
{
"id": 1,
"name": "${faker.name().name()}",
"address": "${faker.address().fullAddress()}",
"phone": "${faker.phoneNumber().cellPhone()}"
},
{
"id": 2,
"name": "${faker.name().name()}",
"address": "${faker.address().fullAddress()}",
"phone": "${faker.phoneNumber().cellPhone()}"
}
]
}
}"""
}
mirage user.mir
$ curl -s http://127.0.0.1:8080/user/1234/get | jq .
$ curl -s http://127.0.0.1:8080/user/1234/get2 | jq .
{
"id": "1234",
"name": "Astn",
"t": "2019-11-17T04:04:55+0000",
"data": {
"contact": [
{
"id": 1,
"name": "Bryan Bashirian",
"address": "22474 Bashirian Ways, New Thanhfurt, MA 32424-5437",
"phone": "(973) 158-7100"
},
{
"id": 2,
"name": "Charley Jast",
"address": "526 Corkery Rue, Lake Moises, MO 28747",
"phone": "1-418-198-2865"
}
]
}
}
欢迎交流和体验使用:Github 地址
1
zthxxx 2019-11-18 19:21:20 +08:00 via iPhone
一眼看成 Nginx
|