Coder Social home page Coder Social logo

realdah / simple-json-replay-server Goto Github PK

View Code? Open in Web Editor NEW
8.0 8.0 2.0 78 KB

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.

JavaScript 100.00%

simple-json-replay-server's People

Contributors

realdah avatar sijeesh-02 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

simple-json-replay-server's Issues

Quick clarification in README

Maybe make the README example more clear by changing:

you can hit http://localhost:8008/test to see the result

to

you can hit http://localhost:8008/test?param1=value1%20to%20be%20matched&param2=value2%20to%20be%20matched to see the result

Pattern matching on data while using POST request instead of exact match.

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:

Capture
Capture
Capture

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 :):)

When several paths are matched, the exact match does not take the precedence

Hello,

Given the 2 following json files, the exact path does not take the precedence if it was registered before:
an.example.query.json
{
"request" : {
"path": "testTest"
},
"response" : {
"status" : 200,
"data" : {
"message" : "you can see this because you used the path 'testTest'"
}
}
}

example.query.json
{
"request" : {
"path": "test"
},
"response" : {
"status" : 200,
"data" : {
"message" : "you get default result. let's try http://localhost:8008/test?aa=123 or http://localhost:8008/test?bb=123 to see what's happen"
}
}
}

When targetting localhost:4200/testTest, I would expect to get the response "you can see this because you used the path 'testTest'"", instead I receive "you get default result. let's try http://localhost:8008/test?aa=123 or http://localhost:8008/test?bb=123 to see what's happen".

It happens because the 2 paths are matched because on line#13 of match.js indexOf is used. Then there is no score on the path itself. Therefore the last one registered will be used.

One way to fix it would be to add a score when the path match exactly with the request.

Best Regards,
Kevin.

Cookie support

Hi,

would it be possible to add cookie support to your mock server? I would like to have the mock service read a cookie and use as a signature to mock out a correct response based on data embedded in the cookie.

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.