Registry / storage / fetch-request

fetch-request

JSON →
library1.2.0jsnpmunverified

A lightweight AJAX component wrapper around the Fetch API, providing a simplified interface for HTTP requests with caching, request/response interceptors, and centralized error handling. Current stable version is 1.2.0. Released as needed with no regular cadence. Key differentiators: ESM-only import style, support for common methods (get, post, put, patch, del), and a configurable response handler for centralized error processing. Less mature than alternatives like axios or ky, minimal documentation.

npm install fetch-request
INSTALL
IMPORT
SIG · FETCH-REQUEST
F
fetch-request
storagejavascriptv1.2.0
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.

setConfig
import { setConfig } from 'fetch-request'
const fetchRequest = require('fetch-request')
ESM-only; no default export, named export only. require() will not work.
get
import { get } from 'fetch-request'
Named export for HTTP GET requests.
post
import { post } from 'fetch-request'
Named export for HTTP POST requests.

Configures the instance with global settings and performs a simple GET request.

import { setConfig, get, post, del, patch, put } from 'fetch-request'; setConfig({ apiHost: 'https://api.example.com/', options: { credentials: 'include' }, cache: true, headers: { Accept: 'application/json' }, errHandle(err) { console.error(err); }, reqHandle(url, options) { console.log(url, options); }, respHandle(resp) { if (resp.errorCode === 200) { return resp.data; } else { const error = new Error(resp.errorMessage || 'Unknown error'); error.resp = resp; throw error; } } }); get('user/info', { id: 123 }).then(data => { console.log(data); });
Debug
Known issues
gotchaThe library uses application/x-www-form-urlencoded format by default. If you need JSON, you must manually set Content-Type header.
fix
Set content-type header in config or per-request options: headers: { 'Content-Type': 'application/json' }
affects: >=1.0.0
breakingOnly supports ESM imports. CommonJS require() will throw an error.
fix
Use import syntax instead of require().
affects: >=1.0.0
gotchaResponse handler (respHandle) expects a specific structure: errorCode, data, errorMessage. Non-standard backends may cause unexpected errors.
fix
Ensure backend returns { errorCode, data, errorMessage } or override respHandle to match your API.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: fetch-request__WEBPACK_IMPORTED_MODULE_0__.default is not a function
Using default import instead of named import
fix
Change 'import fetchRequest from 'fetch-request'' to 'import { get, post, setConfig } from 'fetch-request''
ReferenceError: require is not defined in ES module scope, you can use import instead
Using require() in a browser or ESM environment
fix
Replace require('fetch-request') with import { ... } from 'fetch-request'
Upgrade
Version history
1.2.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
15 hits · last 30 days
node
12
OpenAI (training)
2
Amazon
1
Resources
fetch-request — npm install fetch-request · libregistry