Registry / devops / simple-fetch-wrapper

simple-fetch-wrapper

JSON →
library1.3.8jsnpmunverified

simple-fetch-wrapper v1.3.8 is a lightweight HTTP client wrapping the native fetch API. It provides a simple interface for GET and POST requests, base URL configuration, default content type, request interceptors, a fetching status callback, and a custom event system. Updated infrequently, it offers minimal abstraction compared to axios or ky, with TypeScript declarations included. Good for small projects wanting fetch convenience without heavy dependencies.

npm install simple-fetch-wrapper
INSTALL
IMPORT
SIG · SIMPLE-FETCH-WRAPP
S
simple-fetch-wrapper
devopsjavascriptv1.3.8
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.

default
✓ import http from 'simple-fetch-wrapper'
✗ const http = require('simple-fetch-wrapper')
Package exports default object. CommonJS require works but TypeScript may complain without esModuleInterop.
http.setBaseUrl
✓ http.setBaseUrl('https://api.example.com')
✗ http.setBaseUrl = 'https://api.example.com'
setBaseUrl is a method, not a property assignment.
http.get
✓ const response = await http.get('/users', { params: { id: 1 } })
✗ const response = http.get('/users', { params: { id: 1 } })
get returns a Promise; must be awaited.

Shows base URL setup, content type, fetching status callback, and async GET/POST requests.

import http from 'simple-fetch-wrapper' http.setBaseUrl('https://jsonplaceholder.typicode.com') http.setDefaultContentType('application/json') http.isFetching((status) => { console.log('Fetching:', status) }) const response = await http.get('/posts/1') console.log('GET response:', response) const postResponse = await http.post('/posts', { body: { title: 'foo', body: 'bar', userId: 1 } }) console.log('POST response:', postResponse)
Debug
Known issues
gotchahttp.get and http.post do not include query params automatically; must provide via `params` key in args object.
fix
Include `params` object in args: http.get('/endpoint', { params: { key: 'value' } })
affects: >=1.0.0
gotchahttp.interceptor must return the modified requestConfig; if forgotten, subsequent requests may fail.
fix
Always return the requestConfig object from interceptor function.
affects: >=1.0.0
gotchahttp.isFetching callback receives a boolean but is called multiple times; ensure side effects are idempotent.
fix
Use the callback for UI state updates that can be set repeatedly.
affects: >=1.0.0
gotchaCustom events using http.on/http.emit are in-memory and do not persist across page reloads.
fix
Use for transient app events only; not a replacement for persistent state management.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: http.get is not a function
CommonJS require used without default import; module.exports is an object, not a function.
fix
Use `import http from 'simple-fetch-wrapper'` or `const http = require('simple-fetch-wrapper').default`
TypeError: Cannot read properties of undefined (reading 'then')
Forgetting to await the async http.get or http.post call.
fix
Add `await` before the call: `const res = await http.get(...)`
Error: No base URL set. Use setBaseUrl() first.
Calling http.get or http.post without previously setting a base URL via http.setBaseUrl().
fix
Call http.setBaseUrl('https://base.url') before making requests.
Upgrade
Version history
1.3.8latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
simple-fetch-wrapper — npm install simple-fetch-wrapper · libregistry