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

Support passing an URL instance #41

Closed
groenroos opened this issue Apr 10, 2024 · 1 comment
Closed

Support passing an URL instance #41

groenroos opened this issue Apr 10, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@groenroos
Copy link

It'd be handy if fetch() could also accept a URL instance as the source;

const url = new URL('...');
const data = await fetch(url);

Currently this throws an error:

TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received an instance of URL

Using URL to generate the source URL can be a common use case, in case you need to safely add query parameters, or control the base/host of the request between environments.

I know it's an easy fix to use url.toString() instead, but it can be a gotcha - it'd be a nifty ergonomic improvement if this was handled automagically!

@zachleat zachleat added this to the Eleventy Fetch v5.0.0 milestone May 13, 2024
@zachleat
Copy link
Member

v5.0 will support anything that can be converted via toString 👍🏻

zachleat added a commit that referenced this issue Oct 22, 2024
@zachleat zachleat added the enhancement New feature or request label Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants