ky vs Axios: どちらのHTTPクライアントを選ぶか
kyはretryとhookを備えた小さくモダンなfetchのwrapper、Axiosは幅広い互換性を持つ大きく機能豊富なHTTPライブラリです。
kyはネイティブの fetch API を小さくエレガントなパッケージで包み、retry、タイムアウト、hook、クリーンなメソッドAPIを追加しつつ、ESM-firstで軽量なままです。Axiosはより古く重いですが実戦で鍛えられており、interceptor、幅広い環境サポート、そして巨大なインストールベースを持ちます。kyはサイズとfetch上のモダンなエルゴノミクスで優れ、Axiosは成熟度、エコシステム、幅広い互換性で優れます。
| ky | Axios | |
|---|---|---|
| ベース | ネイティブfetchのwrapper | 独自のXHR/httpコア |
| Bundle size | 極小 | より大きい |
| Retry | 組み込み | plugin/configで対応 |
| 成熟度 | モダン、成長中 | 成熟、巨大なベース |
| 最適な用途 | 軽量なモダンfetchのエルゴノミクス | 幅広い互換性、機能 |
ユースケースとエルゴノミクス
kyは、retryとhookを組み込んだ小さなfetchベースのクライアントが欲しいモダンなESMアプリに適しています。Axiosは、古い環境も含め、最大限の互換性、interceptor、広大なエコシステムを必要とするプロジェクトに適しています。kyは軽量でモダンな選択肢、Axiosは成熟して幅広く互換性のある選択肢です。
テストとCI
どちらもMSWやnockでmockでき、kyのfetchベースはNodeのネイティブfetchと整合します。いずれもmanaged runnerで動作し、高速なrunnerはHTTP統合テストスイートを短縮します。
Decide with your own numbers, not a feature table
Feature comparisons age badly and rarely decide anything, because both tools in a mature category can do the job. What differs is how each behaves on your repository, and that takes one afternoon to measure.
# time a cold install with each candidate, cache cleared
hyperfine --prepare "rm -rf node_modules" --warmup 1 \
"<tool-a> install" "<tool-b> install"
# and the thing CI actually pays for: a cold run with no local cache
docker run --rm -v "$(pwd):/w" -w /w node:22 sh -c "<tool> install"What actually changes when you switch
- Lockfile format. A switch is a one-way door for anyone still on the old tool until everyone migrates, so plan it as a single coordinated change.
- Resolution strictness. Tools differ on whether an undeclared transitive import works, and the stricter one will surface latent bugs as new failures.
- CI cache configuration. The cache path and key differ per tool; carrying over the old ones silently disables caching.
- Everyone on the team and every runner must move together. Pin the version so they cannot drift.
結論
retryとhookを備えた小さくモダンなfetchのwrapperが欲しいなら: ky。最大限の互換性、interceptor、巨大なエコシステムが欲しいなら: Axios。kyは軽さとモダンなfetchを、Axiosは成熟度と幅広さを優先します。