ky vs Axios: qual cliente HTTP?
ky é um wrapper minúsculo e moderno sobre fetch com retries e hooks; Axios é uma biblioteca HTTP maior e rica em recursos com ampla compatibilidade.
O ky envolve a API fetch nativa em um pacote pequeno e elegante, adicionando retries, timeouts, hooks e uma API de métodos limpa, mantendo-se ESM-first e leve. O Axios é mais antigo e pesado, mas comprovado em produção, com interceptors, amplo suporte a ambientes e uma enorme base instalada. O ky ganha em tamanho e ergonomia moderna sobre o fetch; o Axios ganha em maturidade, ecossistema e ampla compatibilidade.
| ky | Axios | |
|---|---|---|
| Base | Wrapper sobre fetch nativo | Núcleo próprio XHR/http |
| Bundle size | Minúsculo | Maior |
| Retries | Embutidos | Via plugin/config |
| Maturidade | Moderno, crescendo | Maduro, base enorme |
| Melhor para | Ergonomia enxuta com fetch moderno | Ampla compatibilidade, recursos |
Caso de uso e ergonomia
O ky se encaixa em apps ESM modernos que querem um cliente minúsculo baseado em fetch com retries e hooks embutidos. O Axios se encaixa em projetos que precisam de máxima compatibilidade, interceptors e um vasto ecossistema, incluindo ambientes mais antigos. O ky é a escolha enxuta e moderna; o Axios é o maduro e amplamente compatível.
Testes e CI
Ambos fazem mock com MSW ou nock; a base fetch do ky se alinha ao fetch nativo do Node. Qualquer um roda em managed runners, onde runners mais rápidos encurtam suítes de teste de integração 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.
O veredito
Quer um wrapper moderno e minúsculo sobre fetch com retries e hooks: ky. Quer máxima compatibilidade, interceptors e um ecossistema enorme: Axios. O ky favorece a leveza e o fetch moderno; o Axios favorece maturidade e abrangência.