a mock server can add apis in seconds with web UI
Mock as Real Server so Soon
soon-admin
vue3 version:https://github.com/leafio/soon-admin-vue3
react version:https://github.com/leafio/soon-admin-react-nextjs
- Add it to your project dev dependencies using NPM:
npm i -D soon-mock
- Add a script to
package.json
,-p can config the server port:
{
"scripts": {
"mock": "soon-mock -p 8080"
}
}
- To start the server by simply running a command in the project folder.
npm run mock
- When the server started, you can just access
http://localhost:8080
in your browser.
-
Switch to
Quick
Tab -
Input
JSON
/JS
like thisuser
,book
are the schema name , just like table in database.
{
user:{
name:'',
age:1,
job:''
},
book:{
author:'',
name:'',
price:1
}
}
- Click the button
Batch Generate
.If a success toast is shown, the APIs has been generated.
Method | Url | Description |
---|---|---|
get | /api/user | list users |
get | /api/user/:id | get user detail |
post | /api/user | add user |
put | /api/user/:id | update user |
delete | /api/user/:id | delete user |
get | /api/book | list books |
get | /api/book/:id | get book detail |
post | /api/book | add book |
put | /api/book/:id | update book |
delete | /api/book/:id | delete book |
-
Switch to
API
Tab, all APIs are shown, and can be edited.
In the action , the code is run in a Express server controller.
You can usereq
to get the request data, and useres
to send the response.
Details usage you can read Express js Documentation. -
Switch to
Schema
Tab, you can modify the schema fields.
In theDefault Value
andMock Data
Input , you can write Single line js code.
Thefaker
,mockjs
anddayjs
are ready for use to create the mock data or value. -
Switch to
Data
Tab, the mock datas are listed. -
Switch to
Config
Tab, these are some default settings.
一个有GUI的的mock服务器
一键模拟真实服务器
soon-admin 后台管理系统
vue3 版:https://github.com/leafio/soon-admin-vue3
react 版:https://github.com/leafio/soon-admin-react-nextjs
- 添加 soon-mock 至项目的 dev dependencies
yarn add soon-mock -D
- 添加一个 script 至
package.json
,-p
可以配置 端口
{
"scripts": {
"mock": "soon-mock -p 8080"
}
}
- 启动 soon-mock 服务
yarn mock
- 当服务启动后, 可在浏览器中访问网址
http://localhost:8080
仅需输入json
,便可批量生成 API。
- 输入如下
JSON
/JS
,user
,book
为 schema 的名称 .
{
user:{
name:'',
age:1,
job:''
},
book:{
author:'',
name:'',
price:1
}
}
- 点击
批量生成
按钮 , 当显示成功提醒后,则下列 API 生成成功HTTP 方法 API 地址 描述 get /api/user 获取 user 列表 get /api/user/:id 获取 user 详情 post /api/user 添加 user put /api/user/:id 修改 user delete /api/user/:id 删除 user get /api/book 获取 book 列表 get /api/book/:id 获取 book 详情 post /api/book 添加 book put /api/book/:id 修改 book delete /api/book/:id 删除 book