当前位置:网站首页>[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
边栏推荐
- C syntax pattern matching [switch expression]
- 如果通过 C# 实现对象的深复制 ?
- 2022年P气瓶充装培训试题及模拟考试
- 求二叉树的叶子结点个数
- js递归树结构计算每个节点的叶子节点的数量并且输出
- LoadRunner - performance testing tool
- MAUI初体验:爽
- 編碼電機PID調試(速度環|比特置環|跟隨)
- 2022 P cylinder filling training test questions and simulation test
- The most understandable life cycle of dependency injection
猜你喜欢

xutils3修改了我提报的一个bug,开心

类似Jira的十大项目管理软件

TP5 inherits base and uses the variables in base

在.NE6 WebApi中使用分布式缓存Redis
![[MySQL] left function | right function](/img/26/82e0f2280de011636c26931a74e749.png)
[MySQL] left function | right function

2022 Shandong Province safety officer C certificate work certificate question bank and online simulation examination

一套组合拳,打造一款 IDEA 护眼方案

Small companies don't make formal offers

全网最全,接口自动化测试怎么做的?精通接口自动化测试详解

編碼電機PID調試(速度環|比特置環|跟隨)
随机推荐
宁德时代地位不保?
MYSQL05_ Ordr by sorting, limit grouping, group by grouping
Source generator actual combat
Aspnetcore configuration multi environment log4net configuration file
Use DFS to solve the problem of "number of dictionary rows"
TP5 email (2020-05-27)
Using positive and negative traversal to solve the problem of "the shortest distance of characters"
类似Jira的十大项目管理软件
The most easy to understand service container and scope of dependency injection
[Mysql] LEFT函数 | RIGHT函数
.NET7之MiniAPI(特别篇):.NET7 Preview3
“如何实现集中管理、灵活高效的CI/CD”在线研讨会精彩内容分享
Improvement of ref and struct in C 11
Use of slice grammar sugar in C #
7-11 重排链表 (25 分)
2022t elevator repair test simulation 100 questions and online simulation test
Systemctl start Prometheus + grafana environment
yes. Net future
Top 9 task management system in 2022
ASP. Net and ASP NETCORE multi environment configuration comparison