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

[q] Way to axios as default library for http requests? #16

Closed
SkeLLLa opened this issue Jul 18, 2022 · 2 comments · Fixed by #17
Closed

[q] Way to axios as default library for http requests? #16

SkeLLLa opened this issue Jul 18, 2022 · 2 comments · Fixed by #17

Comments

@SkeLLLa
Copy link

SkeLLLa commented Jul 18, 2022

Hi.

I see that in current implementation under the hood axios client is used. However since this lib is a client to DB, the performance could be critical.

There's a http client https://github.com/nodejs/undici that doesn't rely on node's http implementation which make it faster. Also it likely become a underlying implementation of fetch in future versions of node.

I see that you're passing in most cases http request function as a dependency, so maybe it worth to allow passing custom request function to connection-factory.ts functions as well? Or just replace axios with undici by default to achieve maximum performance?

@kffl
Copy link
Owner

kffl commented Jul 20, 2022

Hi @SkeLLLa

Thank you for your suggestion. I wasn't aware of that library's existence and have only used axios (somewhat bloaty and opinionated - features some default behaviors that are difficult to opt-out of), node-fetch and Node.js native fetch (a recent addition, still deemed unstable, doesn't support req timeouts and needs AbortController/AbortSignal boilerplate for that purpose) for server-side HTTP requests.

undici looks promising and having seen the benchmarks, I'm certainly in favor of removing axios dependency. It also supports timeouts (with the possibility to set headersTimeout and bodyTimeout separately).

I reckon that the best option would be to use undici by default and also allow the user to optionally pass a custom HTTP GET/POST function that satisfies the type. The latter could be useful i.e. when instrumenting the app for distributed tracing or timing the DB requests for metrics collection.

@SkeLLLa
Copy link
Author

SkeLLLa commented Jul 20, 2022

Node native fetch uses undici under the hood. Undici exposes fetch compatible API as well, but it's not yet stable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants