Open doodirock opened 5 years ago
I has the same need and I though to implement a feature about config routes like a function but reading docs I found middlewares and I guess you can get your need with them like this:
module.exports = (request, response, next) => {
if (request.originalUrl === '/api/tools?id=1') {
response.status(204)
response.end()
} else {
next()
}
}
Down sides?
--watch
options seems do not watch middleware files (but I guess you can overcome using nodemon
instead that option).But thinking better maybe you can do better like this:
module.exports = (request, response, next) => {
const content = require('./custom-responses.js')
if (!content(request, response)) {
next()
}
}
I hope this help you.
It’s the same place I started as well but like you said is very verbose and still takes a lot of manual work when you want to change around multiple scenarios.
For now I think we’re going to move our project to ng-apimock. Thanks for the tips.
On Sep 9, 2019, at 9:39 PM, Hudson Leite notifications@github.com wrote:
I has the same need and I though to implement a feature about config routes like a function but reading docs I found middlewares and I guess you can get your need with them like this:
module.exports = (request, response, next) => { if (request.originalUrl === '/api/tools?id=1') { response.status(204) response.end() } else { next() } } Down sides?
Very verbose; --watch options seems do not watch middleware files (but I guess you can overcome using nodemon instead that option). I hope this help you.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.
I've been looking through the docs and I'm surprised I haven't seen any use cases for this. I'm wondering if anyone has come up with a method to serve chain scenarios when making a request to their json server.
For instance, if my client app makes a get request to an endpoint that has the potential to respond with 6 different status codes, errors, and response types, how do I handle that in my project. At the moment it seems like I have to shut down the server, change what the response is, boot it back up and test.
This gets even more complex if those responses dictate what happens to other responses down the line. So my question is, how are people handling this type of normal workflow? Is there a way to bundle presets ahead of time and change those on the fly similar to ng-apimocks? (https://www.npmjs.com/package/ng-apimock).
E.G.
Our app has a get request to a profile api that returns profile info. In this case we could have a bunch of different responses come back.
400 error 401 auth 200 partial profile data 200 complete profile 500 tech difficulty etc
How do teams normally manage all this without having to stop the server, change the response and test again. How do you test longer chains that affect other responses.