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

extend: append to prefixUrl #586

Open
mfulton26 opened this issue May 14, 2024 · 3 comments
Open

extend: append to prefixUrl #586

mfulton26 opened this issue May 14, 2024 · 3 comments

Comments

@mfulton26
Copy link

I'd like a way to use extend() and append to the existing prefixUrl:

const api = ky.create({ prefixUrl: "https://www.example.com/api" });
const sales = api.extend({ path: "sales/v1" });
await sales.post("offers", { json: {} }); // POSTs to https://www.example.com/api/sales/v1/offers

Today if I use prefixUrl in an extend() call then it overwrites the "base" prefixUrl and I don't see any way to access the configured prefixUrl from the "base" KyInstance. Is this already possible and I've overlooked it?

@sindresorhus
Copy link
Owner

I think something like this would be useful. It should probably be called appendPath to make it clear what it does. I would like to see feedback more people first though.

@DCKT
Copy link

DCKT commented May 21, 2024

+1 ! This functionality can be useful when an API has multiples levels.
I also think this should be under a new function to avoid breaking change and explicit behavior.

@mfulton26
Copy link
Author

kyInstance.appendPath() could be nice (explicit, simple, no changes to extend())

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

3 participants