Switch from got to ky + fetch in notion-client #394
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR removes
got
in favor ofky
innotion-client
. This means thatnotion-client
is no longer tied to Node.js.ky is a thin wrapper around
fetch
, which makesnotion-client
compatible with edge runtimes such as Cloudflare Workers, Vercel edge functions, and Deno.It also adds a secondary entrypoint to
notion-client
which will only be used by "browsers" (and this should include edge runtimes, though this hasn't been tested yet in practice).The node.js entrypoint bundles
ky-universal
, which polyfillsnode-fetch
andabort-controller
for node.js so thatky
works in node.js the same as any otherfetch
-supported environment.The main advantage of using
ky
instead offetch
directly is thatky
includes robustness features such as automatic HTTP status code-aware retrying.The main downside of this change is that
got
is more robust on node.js than any otherfetch
-based HTTP client that I'm aware of, includingky
(thoughky
is the bestfetch
-based HTTP client that I'm aware of).See @remorses previous PR which started this work in #312 and related discussion in #160
cc @pbteja1998 @MartinXPN @on2air