moleculer-web
moleculer-web copied to clipboard
feat(compileRest): allow to reuse the rest settings, to generate rest path from parameters
This PR allow to call a endpoint to generate the rest url .
allow to do :
const svc = {
name: "users",
settings: {
rest: '/users'
},
actions: {
action: {
rest: 'GET /:id'
}
}
}
await ctx.call('gateway.getRest', {action: 'my.action', params: {id:123}}); // => return /users/123
It can be usefull if you want to setup hypermedias, or just generate a link
I'm not sure about the naming, so I reuse the naming from path-to-regexp "compile" .
Not sure about the error throw if missing parameters, but it seems that path-regexp throw an error if a parameter is missing (I also tried with parameter validate to false) .
State of the PR :
- [ ] write tests
- [ ] write documentation
Good idea, please add relevant tests as well