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

Feature Request: Improve URL Construction to Handle Leading Slashes in path Option Gracefully #30

Open
jasonblewis opened this issue Dec 9, 2024 · 1 comment

Comments

@jasonblewis
Copy link

Feature Request: Improve URL Construction to Handle Leading Slashes in path Option Gracefully

Description:

It is easy to mistakenly include a leading slash when specifying the path in request options, like so:

path: `/record/v1/customer/${id}`;

This causes an authentication error when attempting to fetch the result. The issue arises because the leading slash breaks the URL construction process.

Suggested Improvement:

A robust solution would ensure that the URL is constructed correctly regardless of whether the path is provided with or without a leading slash. This could prevent potential errors and improve developer experience.

Potential Implementation:

If there is a built-in Node.js function for constructing URLs that normalizes the path parameter, it might solve this issue seamlessly. For example, leveraging URL or other standard libraries to handle path concatenation could prevent errors like this.

Reference:

The relevant code section can be found here:

if (this.base_url) uri = `${this.base_url}/services/rest/${path}`;

Rationale:

This feature would improve the developer experience and reduce potential pitfalls for users of the library. I'm raising this feature request as a future enhancement and would be happy to contribute a fix at some point.

@julbrs
Copy link
Owner

julbrs commented Dec 12, 2024

Would love a PR ;)

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