当前位置:网站首页>[mock data] fastmock dynamically returns the mock content according to the incoming parameters
[mock data] fastmock dynamically returns the mock content according to the incoming parameters
2022-04-23 03:12:00 【A happy wild pointer D】
The general logic in a project is , The front end initiates a request , The back end receives parameters , After logical processing, the data is returned to the front end . in other words , What data is returned by the back end depends on what data is passed by the front end , therefore ,mock Data time , Dead data have great limitations .fastmock Provides a solution , It supports obtaining data from the request and then returning the corresponding response information .
fastmock The following four types of data are supported :
-
restful Link parameters : Such as /user/1, The corresponding data is {id: 1}, The acquisition method is _req.params.id
-
query Query parameters : Such as /user?username=Amour, The acquisition method is _req.query.username. Commonly used in get request
-
body Request body data : Parameter in request body in , The acquisition method is _req.body.key. Commonly used in post request
-
headers Header information : The acquisition method is _req.headers.key. The common scenario is the interface token verification , The acquisition method is _req.headers.token
Usage method
In the original json Based on the data , The value that needs to be returned dynamically is not a specific value or mock The rules , It's a function , Function takes two parameters , Namely _req and Mock( The variable name cannot be changed )
{
// The two parameters are expressed in {} Wrapped , Don't leave out , Otherwise, an error will be reported
"username":function({_req,Mock}){
from _req The value of
Logical processing
......
Return the data
}
}
function Parameter description
Here's a simple example
stay fastmock Create interface in , The interface contents are as follows :
{
"msg":function({_req,Mock}){
let query = _req.query;
let username = query.username;
let password = _req.query.password;
if (username == "admin" && password == "123456"){
return " Landing successful ";
}else{
return " Wrong user name or password ";
}
}
}
The user is called admin And the password is 123456 when , Return login success information ; Otherwise, the user name or password is wrong
After the interface is created, we go to request . Access directly from the browser , A similar to postman The page of , On the left is the request and response information , On the right are the parameters and methods of sending the request .
It's on it get Requested interface , If it is post request , Will be displayed body Area , You can write parameters here , It won't be spliced to url Yes .
For more information, please see fastmock Out of the document :https://marvengong.gitee.io/fastmock/#/restful
above .
版权声明
本文为[A happy wild pointer D]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220627538360.html
边栏推荐
- Yes Redis using distributed cache in NE6 webapi
- Source generator actual combat
- [new version release] componentone added Net 6 and blazor platform control support
- 全网讲的最细,软件测试度量,怎样优化软件测试成本提高效率---火爆
- 7-11 rearrange the linked list (25 points)
- Creating wechat voucher process with PHP
- After the mobile phone is connected to the computer, how can QT's QDIR read the mobile phone file path
- MYSQL04_ Exercises corresponding to arithmetic, logic, bit, operator and operator
- 求二叉树的叶子结点个数
- Vs code setting line feed
猜你喜欢
准备一个月去参加ACM,是一种什么体验?
一文了解全面静态代码分析
OLED多级菜单记录
由于3²+4²=5²,所以称‘3,4,5‘为勾股数,求n(包括n)以内所有勾股数数组。
C language to achieve address book - (static version)
腾讯视频VIP会员,周卡特价9元!腾讯官方直充,会员立即生效!
C read / write binary file
2022A特种设备相关管理(电梯)上岗证题库及模拟考试
PID debugging of coding motor (speed loop | position loop | follow)
TP5 inherits base and uses the variables in base
随机推荐
2022A特种设备相关管理(电梯)上岗证题库及模拟考试
2022年P气瓶充装培训试题及模拟考试
【新版发布】ComponentOne 新增 .NET 6 和 Blazor 平台控件支持
求二叉树的叶子结点个数
Tencent video VIP member, weekly card special price of 9 yuan! Tencent official direct charging, members take effect immediately!
ASP.NET 6 中间件系列 - 执行顺序
12.<tag-链表和常考点综合>-lt.234-回文链表
交换二叉树中每个结点的左和右
2022年做跨境电商五大技巧小分享
在.NE6 WebApi中使用分布式缓存Redis
Xamarin效果第二十一篇之GIS中可扩展浮动操作按钮
Find the number of leaf nodes of binary tree
搭建XAMPP时mysql端口被占用
Establishing and traversing binary tree
如果通过 C# 实现对象的深复制 ?
“如何实现集中管理、灵活高效的CI/CD”在线研讨会精彩内容分享
ASP. Net 6 middleware series - execution sequence
ASP. Net 6 middleware series - Custom middleware classes
【无标题】
【鉴权/授权】自定义一个身份认证Handler