-
Notifications
You must be signed in to change notification settings - Fork 30k
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
http: Using URL with http.request (feature suggestion) #20795
Comments
Can you provide some sample code showing the way you would like to be able to write calls to |
Seems like a reasonable feature to me but what takes precedence when both Alternative: overload |
I'm 👍 for a 3-arg signature. |
@Trott I was suggesting: const options = { url: new URL('...'), headers: { foo: 'bar' } };
http.request(options, cb); @bnoordhuis Good question, and I think your suggestion for 3-arg is a good alternative that makes the precedence very clear (the URL wins, right? :)). |
Fun fact: in |
Slightly related whatwg/fetch#452 |
@benjamingr Yeah, I think the takeaway there is that the URL is basically expected to be (or is cast to) a string, and |
Fixes: nodejs#20795 PR-URL: nodejs#21616 Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Ron Korving <ron@ronkorving.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Fixes: #20795 PR-URL: #21616 Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Ron Korving <ron@ronkorving.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Backport-PR-URL: #21880 Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Using
URL
objects is clearly the way to go when it comes to dealing with URLs, andhttp.request()
can take aURL
object as input. This is great. But if I want to also send custom headers, I'm stuck. I would like to suggest an option for the options object calledurl
that can be set to URL object and maybe even a string. I don't really want to make an already complex API more complex, but I'm not sure how else we can make it easier to use URL objects with HTTP requests.Feedback, suggestions, thoughts from @nodejs/collaborators very welcome.
The text was updated successfully, but these errors were encountered: