Ky is a minimalist, elegant HTTP client for modern browsers, Node.js, Bun, and Deno, built as a wrapper around the native Fetch API. Its current stable version is 2.0.1, with major releases introducing significant breaking changes (e.g., v2.0.0). Ky distinguishes itself from plain `fetch` by providing a simpler API with convenient method shortcuts (e.g., `ky.post()`), automatic retries for failed requests, treating non-2xx status codes as errors by default, built-in JSON option handling, timeout support, upload/download progress, and a flexible hooks system for extending functionality. It also offers advanced features like base URL options, custom instances, and robust TypeScript generics for response types, significantly reducing boilerplate compared to raw Fetch. The library prides itself on being tiny and having no external dependencies, focusing on core HTTP client functionality.
npm install kyVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to perform both POST and GET requests using Ky, including sending JSON payloads, handling search parameters, setting request timeouts, and configuring automatic retries. It also illustrates robust error handling by catching `HTTPError` instances to access detailed response information in case of non-2xx status codes, showcasing Ky's streamlined API compared to native Fetch.
Upgrade your Node.js runtime to version 22 or later. If unable to upgrade, use `npm install ky@^1`.
Refactor hook functions to destructure the single state object. For example, `(request, options)` becomes `({ request, options })`.Replace all instances of `prefixUrl` in your Ky options with `prefix`. For example, `ky.extend({ prefixUrl: '...' })` becomes `ky.extend({ prefix: '...' })`.Update `beforeError` hook implementations to accept the unified state object. Refer to the Ky documentation for the exact structure of the state object passed to this hook.
Use ES Module import syntax: `import ky from 'ky';` Ensure your project's `package.json` includes `"type": "module"` or uses `.mjs` file extensions for ESM.
Ensure you `await` the Ky request: `const data = await ky.get(url).json();`
Wrap your Ky calls in a `try...catch` block to handle `HTTPError` instances. You can inspect `error.response.status` and `error.response.statusText` for details.
No dependency data recorded yet.