
ky
A tiny HTTP client for JavaScript that wraps the Fetch API with simpler calls and error handling.
- Stars
- 17.1k
- Forks
- 510
- Licence
- MIT
- Language
- TypeScript
- Last update
- 28 days ago
- Type
- Library
What it is
Ky is a small JavaScript library for making HTTP requests, such as loading data from or sending data to a web server. It builds on the browser's built-in fetch function and adds conveniences like JSON handling, automatic retries, timeouts, and treating error status codes as errors. The README says it has no dependencies and works in modern browsers, Node.js, Bun, and Deno.
- Send a JSON POST request and read the JSON reply in one line
- Create an instance with a base URL and default headers for one API
- Retry failed requests and set a timeout on slow calls
- Validate a JSON response against a Zod schema
Great for
- JavaScript or TypeScript developers who already use fetch and want less boilerplate
- Projects that call a REST API and want JSON parsing and error handling in one call
- Developers who want a small package with no dependencies
- Teams that want typed responses or validation with Zod or Valibot via Standard Schema
Not ideal for
- People who are not writing JavaScript or TypeScript code, since this is a code library
- Projects that need a feature the README does not mention, such as a built-in cookie jar, because the README does not cover that
- Anyone needing to support environments without fetch support, since Ky is built on the Fetch API
How to get it
- 1
Install with a package manager
You'll need: Node.js or a modern browser, Bun, or Deno
Install with npm
npm install ky - 2
Run it
- Install the package with npm install ky
- Import it with import ky from 'ky';
- Call ky.get or ky.post with a URL, then .json() on the result
- Handle any HTTPError thrown for non-2xx responses
- 3
Get the most out of it
- Use ky.extend() with baseUrl to create instances for different APIs
- Add hooks to change requests or responses in one place
- Pass a Standard Schema validator such as Zod to .json() for runtime checks
- Use the searchParams and json options instead of building strings by hand
Downloads
Strengths
- Small package with no dependencies, according to the README
- Adds retries, timeouts, hooks, and error handling on top of plain fetch
- Typed responses: .json() defaults to unknown rather than any
Trade-offs
- Requires a runtime with fetch support, so it is not a fit for older environments
- The README describes the next version of Ky, so the docs may differ from the version most people install
- Some features, such as streaming request bodies, depend on browser support the README describes as limited
How it compares
| Project | Stars | Type | Level | Updated | Best for |
|---|---|---|---|---|---|
| ky (this) | 17.1k | Library | beginner | 28 days ago | JavaScript or TypeScript developers who already use fetch and want less boilerplate |
| axios | 109k | Library | beginner | 4 days ago | JavaScript developers calling REST or other HTTP APIs from a browser front end |
| got | 15k | Library | beginner | 7 days ago | Node.js developers who call web APIs from server-side code |
| query | 50.5k | Library | intermediate | 4 days ago | Frontend developers building apps that load data from a server |
| SwiftyJSON | 22.9k | Library | beginner | 3 months ago | Swift developers building iOS, macOS, tvOS or watchOS apps that read JSON from web APIs |
| json-server | 75.7k | Dev tool | beginner | 8 months ago | Front-end developers who need a backend stub while the real API is not ready |
Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.