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

PP-13096: Refactored URL generation. #4254

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

nataliecarey
Copy link
Contributor

WHAT

Refactoring URL generation for readability

I've gone through a number of files, enough to see a range of URLs that I believe are better handled by the new approach.

@@ -0,0 +1,30 @@
function generateUrl (template, urlParams = {}, queryParams = {}) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I take it it doesn't matter what the path params are in the template? For e.g. /v1/{example} would be treated the same way as /v1/{gatewayId}?
Also although there are comprehensive tests for this function I'm finding it really hard to understand how it works.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use's axios to encode query params? Then for the normal url we can revert to

`${this.connectorUrl}/v1/api/accounts/{accountId}/stripe-account`
.replace('{accountId}', encodeURIComponent(gatewayAccountId))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can choose any name for the template variables and they all need to be provided when using the template.

I think it's good to put the full URL generation together in one place rather than splitting some of it out to Axios.

The Axios implementation also does some quite specific things with arrays that I wouldn't expect to be compatible with our Java backends - they remind me of PHP's handling of query strings.

Even if we want to use Axios's approach I'd build it into the generator so it's a centralised change if we want to change it.

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