Evaluate Node-RED as alternative to the fake backend
mischah opened this issue · 3 comments
Evaluate Node-RED as alternative to the fake backend
Does it offer all features our existing fake backend has?
- Possibility to add custom HTTP request headers
- Possibility to define a custom port and and api path prefix
- eg.
http://localhost:8081/myApi
- eg.
- Multiple HTTP methods per endpoint
- URL path parameters with fixed and/or variable path segments.
- eg.
/update/{id}
- eg.
- Optional URL path parameters
- eg.
/update/{id?}
- eg.
- Freely define HTTP status code for the return
- Answer with different HTTP error codes per endpoint
- optionally return custom JSON in an error case
- Check how to integrate in Bootstrap Kickstart
Please export and attach Node-RED config to make the tests reproducible.
I evaluated Node-red as alternative to the fake-backend.
It is possible to integrate node-red to boostrap-kickstart:
- Install node-red and express via npm
- Embed node-red example: Node Red Embedding
In my example attached below i have created endpoints with the same url but different request methods.
Also it is possible to use query, path and optional params for example:
/user/:id
(not optional)
/user/:name?
(optional)
In a function node it is possible to define different HTTP Status codes for example:
msg.statusCode = 200;
or
if (msg.req.params.id == 1234) {
msg.payload.name = "User";
msg.payload.id = 1234 ;
msg.statusCode = 200;
} else {
msg.payload.res = "User not found";
msg.statusCode = 400;
}
return msg;
Click here for an example JSON file
Thanks @DanielBrommer ❤️
@jMengel @mfroehner
As you see it’s possible to replace the fake backend with node-red.
I’m not sure if I would replace it out of the following reasons:
- (For me) its not easier to use
- See example from Daniel
But it definitely has its use cases.
Beside that I would neither integrate our fake-backend nor node-red as dependency.
Both play well together with Baumeister but there aren’t a needed part for each and every project.
Remaining question:
Should we add a Part about faking an API to the Readme?
Going to close this for now. Hit me up if you want to talk about it.