A tiny and elegant JavaScript HTTP client based on the Fetch API with retries, timeouts, and hooks.
Ky is a tiny, elegant HTTP client library for JavaScript and TypeScript, built on top of the standard Fetch API. It simplifies making HTTP requests by providing a cleaner API, automatic retries, timeout handling, and lifecycle hooks, while remaining lightweight and dependency-free. It solves the verbosity and missing features of the native Fetch API for modern web and Node.js development.
JavaScript and TypeScript developers building applications for browsers, Node.js, Bun, or Deno who need a robust, modern HTTP client with better ergonomics than Fetch. It's ideal for projects prioritizing minimal bundle size and standards compliance.
Developers choose Ky over alternatives because it offers a perfect balance of simplicity and power: it's smaller and more standards-aligned than Axios, more browser-friendly than Got, and provides essential features like retries, hooks, and excellent TypeScript support out of the box.
🌳 Tiny & elegant JavaScript HTTP client based on the Fetch API
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Ky reduces Fetch boilerplate with method shortcuts like `ky.post()` and automatic JSON handling, making code cleaner and more declarative as shown in the usage comparison.
It offers configurable retries with exponential backoff, jitter, and custom delay functions, supporting scenarios like rate limiting and network errors, detailed in the retry options.
Lifecycle hooks such as `beforeRequest` and `afterResponse` enable interception and modification, allowing for token refresh, caching, and mocking without cluttering core logic.
Ky provides generics for JSON responses, defaults to `unknown` for safety, and includes typed error classes like `HTTPError`, ensuring full type coverage in modern TypeScript projects.
Features like HTTP/2 or proxy support in Node.js require integrating third-party libraries like undici and custom dispatchers, adding complexity beyond the base package.
When retries are enabled, Ky buffers entire ReadableStream bodies in memory using `tee()`, which can cause performance issues for large uploads, forcing users to disable retries.
The hooks system, while powerful, involves multiple hook types and state objects that can be overwhelming for simple use cases, leading to a steeper learning curve than basic Fetch wrappers.
ky is an open-source alternative to the following products:
Axios is a popular promise-based HTTP client for JavaScript and Node.js, used for making HTTP requests from browsers and Node.js environments.
got is a human-friendly and powerful HTTP request library for Node.js that simplifies making HTTP requests with a streamlined API and promise support.