Ky
A friendlier version of the standard fetch function used to request data from other websites or servers.
Ky
General JSA friendlier version of the standard fetch function used to request data from other websites or servers.
Fit
Bundle (gzip)
7.2 kB
20.6 kB raw
Install size includes transitive dependencies. Bundle size is gzipped browser payload.
Freshness
The Problem
Communicating with web APIs using the native fetch() function often becomes a repetitive and frustrating chore due to its lack of built-in convenience features, such as automatic JSON parsing or easy error handling. This hassle is compounded when you need a solution that remains consistently high-performing across different runtimes and environments. The challenge is finding a tool that simplifies the boilerplate of network requests while maintaining the broad compatibility and efficiency required for modern, professional web development.
What It Does
Ky transforms the standard fetch experience by wrapping it in a developer-friendly interface that eliminates common pain points like manual response processing and complex timeout configurations. It solves the issue of repetitive "fetch" logic by providing sensible defaults and a cleaner syntax, while remaining remarkably lightweight to ensure top-tier performance. Because it is built on top of native fetch standards, it guarantees wide compatibility across various environments, allowing you to handle API communication reliably without the weight of massive traditional libraries.
Installation
npm i kyUsage Example
Traditionally, using plain fetch() you will need to write like this :
class HTTPError extends Error {}
const response = await fetch("https://example.com", {
method: "POST",
body: JSON.stringify({ foo: true }),
headers: {
"content-type": "application/json",
},
});
if (!response.ok) {
throw new HTTPError(`Fetch error: ${response.statusText}`);
}
const json = await response.json();
console.log(json);But with Ky, it can be simplified into :
import ky from "ky";
const json = await ky
.post("https://example.com", { json: { foo: true } })
.json();
console.log(json);Related packages
Unified TypeScript SDK for building AI-powered apps — switch between 20+ LLM providers without rewriting code.
animejsGeneral JSLightweight JavaScript animation library with a tiny footprint and a powerful, expressive API.
AOSGeneral JSAn easy-to-use library that makes elements fade, slide, or zoom into view as the user scrolls down your page.
archiverGeneral JSStreaming interface for generating ZIP and TAR archives in Node.js — create compressed archives programmatically from files, directories, and buffers.
@formkit/auto-animateGeneral JS> Add smooth transitions to any element with a single line — zero-config animations for adds, removes, and moves.