A simple json replay server which can be used for developing single page application (angular/reactjs/vuejs especially) without services dependency. Simply put the url & response json data, then route your service calls to this mock server, whenever it matches the url with other optional filtering rules, it will return the matching json data.
8
stars
2
forks
source link
Pattern matching on data while using POST request instead of exact match. #7
I am a great fan of this library and I use it a lot in my current projects. I had a small suggestion like in general we will not use exact data in post request I will change continuously based on data.
why can we implement pattern matching instead of exact match in the data field, actually it helps developers a lot while doing form operations? for that, I have written a logic in utils.js file in your code which is working fine as expected for me. please add the below code at line 45 to get the solution.
{
"request" : {
"path": "test2",
"method": "post",
"body": {
"name": "Realdah",
"password": 1234,
"message": "/^[A-Z]+[A-Z]$/"
}
},
"response" : {
"status" : 200,
"data" : {
"message" : "you can see this because you used post method with pattern matching data",
"key" : "this is a post example with pattern matching data"
}
}
}
please follow below link for screenshots:
Thanks and Regards,
Viswa.
Note: it might be best if u have done the same implementation for query parameters also.
Definitely after adding these features this library will become so popular on all nodejs frontend technologies :):)
Hi Realdah,
I am a great fan of this library and I use it a lot in my current projects. I had a small suggestion like in general we will not use exact data in post request I will change continuously based on data. why can we implement pattern matching instead of exact match in the data field, actually it helps developers a lot while doing form operations? for that, I have written a logic in utils.js file in your code which is working fine as expected for me. please add the below code at line 45 to get the solution.
else if(((typeof value) === 'string') && value.startsWith("/")){ if(fullObjectValue.match(value.substr(1, value.length-2))){ return false; }else{ match = -1; return true; } }
and mock json file:
{ "request" : { "path": "test2", "method": "post", "body": { "name": "Realdah", "password": 1234, "message": "/^[A-Z]+[A-Z]$/" } }, "response" : { "status" : 200, "data" : { "message" : "you can see this because you used post method with pattern matching data", "key" : "this is a post example with pattern matching data" } }
}
please follow below link for screenshots:
Thanks and Regards, Viswa.
Note: it might be best if u have done the same implementation for query parameters also.
Definitely after adding these features this library will become so popular on all nodejs frontend technologies :):)