Pular para o conteúdo
LatchkeyLatchkey home

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.

kyAxios
BaseWrapper sobre fetch nativoNúcleo próprio XHR/http
Bundle sizeMinúsculoMaior
RetriesEmbutidosVia plugin/config
MaturidadeModerno, crescendoMaduro, base enorme
Melhor paraErgonomia enxuta com fetch modernoAmpla 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.

Terminal
# 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.

Perguntas frequentes

ky vs Axios: Which HTTP Client?
ky wraps the native fetch API in a small, elegant package, adding retries, timeouts, hooks, and a clean method API while staying ESM-first and lightweight. Axios is older and heavier but battle-tested, with interceptors, wide environment support, and a huge install base.
Use case and ergonomics?
ky suits modern ESM apps wanting a tiny fetch-based client with built-in retries and hooks. Axios suits projects needing maximum compatibility, interceptors, and a vast ecosystem, including older environments. ky is the lean modern choice; Axios is the mature, broadly compatible one.
Testing and CI?
Both mock with MSW or nock; ky's fetch base aligns with native Node fetch. Either runs on managed runners, where faster runners shorten HTTP integration test suites.
Which should I choose?
Want a tiny, modern fetch wrapper with retries and hooks: ky. Want maximum compatibility, interceptors, and a huge ecosystem: Axios. ky favors leanness and modern fetch; Axios favors maturity and breadth.

Guias relacionados