by vee

Got is a powerful, feature-rich HTTP client for Node.js with support for retries, pagination, streaming, RFC-compliant caching, hooks, and TypeScript out of the box.
Got is a human-friendly, feature-rich HTTP request library for Node.js with built-in support for retries, timeouts, pagination, streaming, caching, and JSON handling. This block delivers the full Got source so you can vendor it, fork it, or embed it directly in a Node.js backend or service layer. Target buyer is a Node.js/TypeScript developer who needs reliable HTTP requests with fine-grained control over redirects, retries, and response parsing.
source/index.ts — Public entry point; re-exports everything from sub-modules and creates the default got instance.source/create.ts — Factory function that builds a Got instance from InstanceDefaults; powers got.extend() and alias methods.source/types.ts — Top-level TypeScript types: InstanceDefaults, HandlerFunction, Got, GotReturn, ExtendOptions, GotPaginate, GotStream, etc.source/as-promise/ — Wraps the core Request duplex stream into a Promise-based interface with retry logic and body parsing.source/as-promise/index.ts — asPromise<T>() implementation; handles response body decoding, retries, redirects.source/as-promise/types.ts — RequestPromise<T> interface and related promise-side types.source/core/ — Low-level HTTP engine: options normalization, error classes, caching, timeout, diagnostics.source/core/index.ts — Request class (extends Duplex); core HTTP dispatch, redirect following, upload/download progress.source/core/options.ts — Options class with full option normalization; exports OptionsInit, NormalizedOptions, RetryOptions, etc.source/core/errors.ts — All named error classes: RequestError, HTTPError, TimeoutError, CacheError, ReadError, MaxRedirectsError, UploadError, RetryError, AbortError, ParseError.source/core/response.ts — / types, body decode helpers, , .Spin up an isolated sandbox and run it server-side — no local setup.
Tetrees AI Review of this version
This TypeScript cli / script completed archive review. Structure, dependency manifests, documentation, functional source, and common risk patterns were checked by the Tetrees verification pipeline; runtime phases are stated separately.
Deterministic AVCP artifact review
Pipeline avcp-2026-08-04.1 · SHA-256 57ff65e9e4677834…
This version-scoped review deterministically inspects the submitted archive for structure, dependencies, documentation, functional source, and common malicious or high-risk signals. Build and test phases are reported as passed only after an isolated sandbox audition. It is not a guarantee of perfect security.
Reviewed Aug 4, 2026
Push this product straight into your AI IDE, web builder or cloud IDE.
Connect Tetrees to a compatible AI IDE, list products you own, and request the verified ZIP without exposing seller upload controls.
No reviews yet.
Sign in to join the discussion
Loading discussion…
ResponsePlainResponseisResponseOkparseBodysource/core/timed-out.ts — Per-phase timeout enforcement; exports Delays type.source/core/calculate-retry-delay.ts — Default retry delay calculator; exported as calculateRetryDelay.source/core/diagnostics-channel.ts — Node.js diagnostics_channel hooks for observability.source/core/parse-link-header.ts — RFC 5988 Link header parser; exported as parseLinkHeader.source/core/utils/ — Internal helpers: timer, get-body-size, proxy-events, defer-to-connect, weakable-map, options-to-url, strip-url-auth, is-unix-socket-url, is-client-request, unhandle.npm install @sindresorhus/is byte-counter cacheable-lookup cacheable-request chunk-data decompress-response http2-wrapper keyv lowercase-keys responselike type-fest uint8array-extras
No native build steps, pod installs, or Android linking required. This is pure Node.js ESM. Node.js 18+ is required (uses node:events addAbortListener, native AbortController, etc.).
source/ into your project, e.g. src/got/.tsconfig.json targets ESM and enables path resolution:{
"compilerOptions": {
"module": "NodeNext",
"moduleResolution": "NodeNext",
"target": "ES2022",
"strict": true
}
}
"type": "module" to your package.json (Got is native ESM; no CJS export).got to src/got/index.ts:{
"compilerOptions": {
"paths": {
"got": ["./src/got/index.ts"]
}
}
}
CookieJar or custom cache adapter via Options.got (default export)import got from './src/got/index.js';
// got(url, options?) => RequestPromise<unknown>
// got.get / .post / .put / .patch / .delete / .head
// got.stream(url, options?) => Request (Duplex stream)
// got.paginate(url, options?) => AsyncIterableIterator<T>
// got.extend(options | Got) => Got
The pre-built Got instance. Use it directly for one-off requests or as the base for got.extend() to create scoped instances with shared defaults.
Optionsimport Options from './src/got/core/options.js';
// new Options(url?, optionsInit?, parent?)
A class that normalizes and merges all request options (URL, headers, retry, timeout, hooks, auth, proxy, etc.). Pass an OptionsInit plain object or compose from a parent Options instance. Use when building reusable option sets or custom Got instances via create().
createimport create from './src/got/create.js';
import type { InstanceDefaults } from './src/got/types.js';
// create(defaults: InstanceDefaults) => Got
Builds a fully functional Got instance from scratch. Use when you need a custom handler pipeline (handlers array), mutable defaults, or complete isolation from the default got instance.
calculateRetryDelayimport calculateRetryDelay from './src/got/core/calculate-retry-delay.js';
// calculateRetryDelay(retryObject: RetryObject) => number (ms)
Default exponential-backoff retry delay function. Override it via options.retry.calculateDelay to implement custom back-off strategies (e.g. honour Retry-After headers).
parseLinkHeaderimport parseLinkHeader from './src/got/core/parse-link-header.js';
// parseLinkHeader(header: string) => Array<{url: string, rel: string, [key: string]: string}>
Parses RFC 5988 Link response headers into structured objects. Useful for pagination via Link: <next>; rel="next" without enabling the full pagination API.
A basic authenticated GET that parses a JSON response body with full TypeScript types.
import got from './src/got/index.js';
type Repo = { full_name: string; stargazers_count: number };
const repo = await got('https://api.github.com/repos/sindresorhus/got', {
headers: { Authorization: `Bearer ${process.env.GITHUB_TOKEN}` },
}).json<Repo>();
console.log(repo.full_name, repo.stargazers_count);
Create a reusable API client that retries on 429/5xx, sets a base prefix, and attaches auth headers globally.
import got from './src/got/index.js';
import type { Delays } from './src/got/core/timed-out.js';
import type { RetryOptions } from './src/got/core/options.js';
const retry: RetryOptions = {
limit: 3,
statusCodes: [429, 500, 502, 503, 504],
methods: ['GET', 'POST'],
};
const timeout: Delays = { request: 10_000 };
const api = got.extend({
prefixUrl: 'https://api.example.com/v1',
headers: { 'X-Api-Key': process.env.API_KEY ?? '' },
retry,
timeout,
});
const users = await api.get('users').json<{ id: string }[]>();
console.log(users);
Use the stream API to pipe a large file to disk, tracking download progress.
import { createWriteStream } from 'node:fs';
import { pipeline } from 'node:stream/promises';
import got from './src/got/index.js';
const download = got.stream('https://releases.ubuntu.com/22.04/ubuntu-22.04.3-live-server-amd64.iso');
download.on('downloadProgress', ({ transferred, total, percent }) => {
process.stdout.write(`\rDownloaded ${(percent * 100).toFixed(1)}% (${transferred}/${total})`);
});
await pipeline(download, createWriteStream('/tmp/ubuntu.iso'));
console.log('\nDone.');
got.paginateIterate through all pages of a paginated REST API without loading all results into memory.
import got from './src/got/index.js';
type Item = { id: number; name: string };
const allItems: Item[] = [];
for await (const item of got.paginate<Item>('https://api.example.com/items', {
searchParams: { per_page: 100 },
pagination: {
transform: (response) => (response.body as unknown as Item[]),
paginate: ({ response }) => {
const link = response.headers['link'] ?? '';
const next = link.match(/<([^>]+)>;\s*rel="next"/)?.[1];
return next ? { url: next } : false;
},
},
})) {
allItems.push(item);
}
console.log(`Fetched ${allItems.length} items`);
source/index.ts — Creates the default got instance using create() and re-exports the entire public surface.source/create.ts — Contains the create(defaults) factory; wires up HTTP method aliases, stream(), paginate(), and extend().source/types.ts — Defines InstanceDefaults, HandlerFunction, GotReturn, ExtendOptions, Got, GotPaginate, GotStream, GotRequestFunction, OptionsWithPagination, StreamOptions.source/as-promise/index.ts — asPromise<T>(): wraps a Request stream into a cancellable Promise with retry loop, redirect handling, and response body decoding.source/as-promise/types.ts — RequestPromise<T> (Promise + .json(), .text(), .buffer() helpers) and supporting types.source/core/index.ts — Request extends Node.js Duplex; full HTTP dispatch lifecycle, cookie handling, caching, timeout enforcement, redirect following.source/core/options.ts — Options class and all option normalization logic; exports OptionsInit, NormalizedOptions, RetryOptions, PaginationOptions, and helpers like isSameOrigin, applyUrlOverride.source/core/errors.ts — Typed error hierarchy: RequestError (base), HTTPError, TimeoutError, CacheError, ReadError, MaxRedirectsError, UploadError, RetryError, AbortError, ParseError.source/core/response.ts — Response/PlainResponse types, isResponseOk(), parseBody(), decodeUint8Array(), cacheDecodedBody().source/core/timed-out.ts — Attaches per-phase timeouts (connect, send, response, etc.) to a ClientRequest; exports Delays type.source/core/calculate-retry-delay.ts — Default exponential back-off with jitter; respects Retry-After headers.source/core/diagnostics-channel.ts — Publishes request lifecycle events to node:diagnostics_channel for APM/tracing.source/core/parse-link-header.ts — Lightweight RFC 5988 Link header parser used by the pagination engine.source/core/utils/ — Small focused utilities: timer (request phase timings), get-body-size, proxy-events, defer-to-connect, weakable-map, options-to-url, strip-url-auth, is-unix-socket-url, is-client-request, unhandle.require() fails at runtime — Got is native ESM only; add "type": "module" to package.json and use .js extensions in all imports.tsconfig moduleResolution must be NodeNext or Bundler — Classic node resolution cannot resolve the .js extension ESM imports; switch to "moduleResolution": "NodeNext".cacheable-request peer expects a specific keyv version — Pin keyv to the same major version required by cacheable-request (^4) to avoid duplicate keyv instances silently breaking cache.decompress-response not stripping content-encoding header — Occurs when options.decompress is false but you call .json(); set decompress: true (the default) or manually handle the raw buffer.retry.methods includes idempotent methods only; explicitly pass methods: ['GET'] if you want to restrict retry scope.got.paginate terminates early with false — Your pagination.paginate function must return false (not undefined) to signal the last page; returning undefined also stops iteration but is semantically ambiguous.I have vendored the Got HTTP library source into `src/got/` in my project.
The integration guide is in `USAGE.md` (also in this context).
The upstream package is `user@example.com` by sindresorhus.
Please help me integrate it step-by-step:
1. Read `USAGE.md` and `src/got/index.ts` to understand the exported API.
2. Install all required dependencies listed in the "Required dependencies" section of USAGE.md.
3. Update my `tsconfig.json` and `package.json` as described in "Project setup".
4. Create a typed API client in `src/lib/http.ts` using `got.extend()` with:
- A `prefixUrl` read from `process.env.API_BASE_URL`
- An `Authorization` header from `process.env.API_TOKEN`
- Retry limit of 3 on 5xx status codes
- A 15-second request timeout
5. Add a helper function `fetchJson<T>(path: string, options?): Promise<T>` that wraps the client.
6. Show me a usage example for a POST request with a JSON body.
7. Show me how to handle `HTTPError` and `TimeoutError` from `src/got/core/errors.ts` distinctly.
Do not invent any APIs. Only use symbols visible in `src/got/index.ts` and `USAGE.md`.
Got is released under the MIT License. See source/LICENSE if present, or refer to the upstream repository. Upstream npm package: got by Sindre Sorhus and contributors.
This product’s unique contribution is clean room implementation of valuable code block into AVCP compatible standard.
The full install guide and integration prompts unlock after purchase.
Automation, Utilities & Developer Tools
Free