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

Path variables à la express #58

Closed
enricodeleo opened this issue Dec 29, 2020 · 7 comments
Closed

Path variables à la express #58

enricodeleo opened this issue Dec 29, 2020 · 7 comments

Comments

@enricodeleo
Copy link

enricodeleo commented Dec 29, 2020

In Express environment is common to express routes like /user/:userId/group where userId is a variable that can be used across middlewares.

I would find awesome an interface like

{
    pathRegex: '',
    prefix: '/users/:userId/group',
    target: `http://targetwebsite.com/group?withuser=${userId}`,
}

Would it be possible?

@jkyberneees
Copy link
Collaborator

Hi @enricodeleo, unfortunately this feature is not implemented at the moment.
However, you can make use of the onRequest hook to modify the request URL as desired.

Can you check that it works for you?

@enricodeleo
Copy link
Author

Yes I think I'll end up using that hook like I did for response transformations.

Actually, I think the my proposed interface is near to be available, at least the prefix part is already working.

In fact, in this scenario

{
    pathRegex: '/:group/:id/products',
    prefix: '/partners',
    prefixRewrite: '/api/v1.0/partners',
    target: API_HOST,
    hooks: {
      rewriteRequestHeaders(req, headers) {
        req.log.debug(req);
        headers['accept-encoding'] = 'identity';
        return headers;
      },
    },
  },

I can see params: { group: 'whatever', id: 'whatever' }, as expected within req.

The only part missing is a function that would parse target url as well. It would be super helpful when using fast-gateway as a migration tool for legacy apis (you could use it in order to listen to request urls in a more "standard" way and then piece by piece migrate each endpoint to its own microservice).

@jkyberneees
Copy link
Collaborator

I understand and I agree with you, let me come up with a flexible approach to update the path or request url without going into the hooks...

Stay tuned

@enricodeleo
Copy link
Author

Any chances you had some idea on how to address it?

@jkyberneees
Copy link
Collaborator

jkyberneees commented Jan 30, 2021

Hi @enricodeleo, excuse me for the delay on this.

What do you think about this proposal?
#61

@enricodeleo
Copy link
Author

no reason to excuse, you already gave us a great tool! so thank you for the time you spent into this new feature. It does look like a great api !

@jkyberneees
Copy link
Collaborator

Hi @enricodeleo, the new urlRewrite hook is now available in v2.8.0. Thanks for your input!
Have fun ;)

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

No branches or pull requests

2 participants