🌳 Tiny & elegant JavaScript HTTP client based on the Fetch API
Features
Fetch-Based HTTP Clients - An HTTP client built on the Fetch API that simplifies requests with automatic error handling and retry logic.
Fetch API Wrappers - Wraps the native Fetch API with a cleaner interface, adding automatic error handling and retry logic.
Request Retries - Automatically retries failed requests with configurable limits, delays, backoff, and jitter.
Automatic Retry Clients - Automatically retries failed requests with configurable limits, delays, and jitter.
Configurable Retry Engines - Provides automatic retry of failed HTTP requests with configurable limits, delays, backoff, and jitter.
Configurable Retry Engines - Ky controls retry behavior with configurable limits, status codes, delays, jitter, and timeout handling to automatically retry failed requests.
HTTP Client Libraries - An HTTP client library built on the Fetch API for making requests with retries, timeouts, and error handling.
Request Cancellations - Leverages the standard AbortController API to cancel in-flight HTTP requests.
Client Instance Defaults - Builds reusable Ky instances with custom defaults supporting inheritance and option replacement.
HTTP Lifecycle Hooks - Allows request and response interception through lifecycle hooks for customization and authentication.
HTTP Retry Engines - Implements automatic retries with configurable limits, status codes, delays, jitter, and timeout handling.
Per-Attempt Timeouts - Applies per-attempt and total timeouts to requests, throwing a timeout error if the limit is exceeded.
Lightweight HTTP Clients - A minimal HTTP client for making requests with JSON handling, timeouts, and configurable retries.
HTTP Client Requests - Ky makes HTTP requests with a clean API, automatic error handling, retries, and timeouts for web and Node.js applications.
HTTP Error Handling - Ky controls how non-2xx status codes are handled with selective error throwing and retry logic for failed requests.
Request Cancellation - Ky aborts an in-flight request using the AbortController API, throwing an AbortError.
Request Lifecycle Hooks - Exposes hooks at initialization, before request, before retry, before error, and after response stages.
Base URL Mappers - Resolves relative request URLs against a specified base URL to simplify API endpoint configuration.
Standard Schema Validators - Validates JSON response bodies against Standard Schema libraries like Zod, throwing a validation error on mismatch.
JSON Request Serializers - Ky automatically serializes JavaScript objects to JSON and sets the appropriate Content-Type header for request bodies.
Hook-Triggered Retries - Ky triggers a retry from an afterResponse hook based on response content, even for successful status codes.
Bidirectional Progress Tracking - Ky reports progress of data transfer with percentage, bytes transferred, and chunk data for both uploads and downloads.
Automatic Token Refreshes - Refreshes expired authentication tokens by intercepting 401 responses and retrying requests with fresh credentials.
Hook-Based Token Refreshes - Retries requests with fresh authentication tokens when a 401 response is received, using before-retry hooks.
Response Schema Validators - Validates JSON response bodies against a schema, throwing an error on mismatch.
Fetch Function Mocking - Replaces the fetch function with a custom implementation to return predefined responses without network calls.
AbortController-Based Clients - Uses the standard AbortController API for consistent request cancellation across environments.