snapreq is a cross-platform HTTP and WebSocket client with a single API across Node.js, web browsers, Expo, and React Native. Current stable version 0.0.5. It picks the right transport (Node http/https, fetch, or XMLHttpRequest) at runtime and zero runtime dependencies. Unlike alternatives (ky, got, node-fetch), snapreq enforces API consistency by raising SnapReqUnsupportedFeatureError for platform-specific gaps (e.g., Unix sockets in browsers) instead of silently changing behavior. ESM-only with JSDoc types checked by tsc. No barrel entry point; imports from subpaths to enable tree-shaking. Supports retry, timeouts, Unix sockets, TLS configuration, request cancellation, streaming, and automatic JSON parsing.
npm install snapreqNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows creating a SnapReq client with a base URL from environment, making a GET request with a timeout, parsing JSON, and handling errors.
Use import syntax or dynamic import(). If you must use require, consider using snapreq with a bundler that can transpile ESM.
Use import SnapReq from 'snapreq' without curly braces.
Wrap platform-specific calls in try-catch and handle SnapReqUnsupportedFeatureError gracefully, or check transport mode before using Node-only features.
Avoid using retry with streamed responses. If retry is needed, consume the response fully before accessing the body.
Explicitly set timeoutMs: 0 on the client if you want no timeout globally, or use a large value like Number.MAX_SAFE_INTEGER.
Either check response.ok or set throwOnError: true on the client or per request.
Run 'npm install snapreq' and ensure your project uses a module bundler that supports ESM subpath exports (e.g., webpack 5+, Node 12+).
Change to: import SnapReq from 'snapreq'
Use response.bytes() instead for cross-platform binary data, or check transport before calling buffer().
Ensure you are running Node 18+ (which has native fetch) or in a browser context with XMLHttpRequest. Polyfills may be needed for older environments.
Use default import: import SnapReqWebSocketClient from 'snapreq/websocket'
No dependency data recorded yet.