Registry / devops / fetch-s

fetch-s

JSON →
library1.3.1jsnpmunverified

fetch-s is a lightweight HTTP client built on top of the Fetch API, providing a Promise-based interface for making requests in browser and Node.js environments. Current stable version 1.3.1. It offers features like request timeout, interceptors, configurable defaults, and JSONP support. Unlike axios or ky, fetch-s retains native Fetch API response types and does not bundle a polyfill, making it smaller. Release cadence is intermittent. Maintained as a hobby project.

npm install fetch-s
INSTALL
IMPORT
SIG · FETCH-S
F
fetch-s
devopsjavascriptv1.3.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

fetchs
import fetchs from 'fetch-s'
import { fetchs } from 'fetch-s'
Default export; named import will result in undefined. ESM and CJS both export a default object.
default (fetchs)
const fetchs = require('fetch-s')
const fetchs = require('fetch-s').default
CommonJS require returns the default export directly, no .default needed.
RequestConfig type
import type { RequestConfig } from 'fetch-s'
import { RequestConfig } from 'fetch-s'
Type imports should use `import type` to avoid runtime errors; named import of type will be undefined at runtime in some bundlers.

Shows GET, POST with timeout, and JSONP requests including error handling. Demonstrates default import and config options.

import fetchs from 'fetch-s'; async function getUsers() { try { const response = await fetchs.get('/users', { data: { page: 1 }, timeout: 5000 }); console.log('Users:', response.data); } catch (error) { console.error('Request failed:', error); } } async function postLogin() { try { const response = await fetchs.post('/login', { userName: 'admin', password: process.env.PASSWORD ?? 'secret' }, { headers: { 'Content-Type': 'application/json' } }); console.log('Login success:', response.data); } catch (error) { console.error('Login failed:', error); } } async function jsonpExample() { try { const response = await fetchs.jsonp('/api', { data: { callback: 'handleJSONP' } }); console.log('JSONP response:', response.data); } catch (error) { console.error('JSONP failed:', error); } } getUsers(); postLogin(); jsonpExample();
Debug
Known issues
gotchafetch-s does not automatically stringify request bodies; you must set Content-Type header for non-form data.
fix
When posting JSON, explicitly set headers: { 'Content-Type': 'application/json' } and use JSON.stringify(data) if needed, though fetch-s does not auto-stringify.
affects: >=1.0.0
breakingIn v1.0.0, the default export was named `fetchs`, but earlier versions may have used a different name or pattern.
fix
Update imports to use the default export as `fetchs` or check the version: `import fetchs from 'fetch-s'`.
affects: <1.0.0
gotchafetch-s uses native Fetch API which requires a polyfill for older browsers (e.g., IE11) and Node.js versions <18.
fix
If targeting older environments, install a fetch polyfill (e.g., cross-fetch, whatwg-fetch) and import it before fetch-s.
affects: >=1.0.0
deprecatedThe `data` property in config is used for request parameters; for methods like GET, it's appended to URL, but for POST it's sent as body. Documentation may be unclear.
fix
Use `data` for both URL params (GET) and body (POST). To avoid confusion, explicitly use `params` for URL params (not supported) or set method accordingly.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Failed to construct 'Request': Request with GET/HEAD method cannot have body.
Passing a body (e.g., data object) in a GET request is not allowed by the Fetch API.
fix
For GET requests, ensure `data` is empty or use `params` (not supported; use URLSearchParams or manually append to URL). fetch-s may attach data to the request body incorrectly.
Uncaught (in promise) TypeError: fetch is not defined
Native fetch is not available in the execution environment (e.g., older Node.js <18).
fix
Install a fetch polyfill like 'node-fetch' or 'cross-fetch' and import it before fetch-s, or upgrade Node.js to v18+.
Cannot read properties of undefined (reading 'then')
Using a named import `{ fetchs }` instead of default import, resulting in `undefined`.
fix
Change import to default import: `import fetchs from 'fetch-s';`
Upgrade
Version history
1.3.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
fetch-s — npm install fetch-s · libregistry