Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(compileRest): allow to reuse the rest settings, to generate rest path from parameters #336

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

thib3113
Copy link
Contributor

@thib3113 thib3113 commented Sep 28, 2023

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

@icebob
Copy link
Member

icebob commented Oct 1, 2023

Good idea, please add relevant tests as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants