Registry / testing / fetch-plugin

fetch-plugin

JSON →
library1.2.8jsnpmunverified

fetch-plugin extends whatwg-fetch to add timeout support, JSONP requests, and global configuration similar to jQuery's ajaxSetup. Version 1.2.8, last updated in 2018. It provides methods like getJSON, postJSON, putJSON, deleteJSON, and getJSONP. Release cadence is sparse. Key differentiators: built-in timeout and JSONP support, global option merging. Suitable for legacy browsers or projects needing a simple fetch wrapper with these features. Note: the package is unmaintained and uses outdated dependencies.

npm install fetch-plugin
INSTALL
IMPORT
SIG · FETCH-PLUGIN
F
fetch-plugin
testingjavascriptv1.2.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.

fetch
✓ import fetch from 'fetch-plugin'
✗ const { fetch } = require('fetch-plugin')
Default export is the fetch object with added methods (getJSON, postJSON, etc.). CommonJS require works but destructuring may not work as expected because the default export is a function with properties.
fetch
✓ const fetch = require('fetch-plugin')
✗ const fetch = require('fetch-plugin').default
In CommonJS, require returns the default export directly, so .default is incorrect.
fetch.getJSON
✓ fetch.getJSON(url, data, options)
✗ fetch.getJSON(url, options, data)
The method signature expects optional data as second argument and optional options as third.

Demonstrates setting global options via fetch.globalOption and using getJSON, postJSON, and getJSONP methods with promise-based API.

import fetch from 'fetch-plugin'; // Set global options fetch.globalOption = { timeout: 5000, fetchStart: () => console.log('Request started'), fetchSuccess: (response) => console.log('Success', response), fetchError: (error) => console.log('Error', error.message), }; // GET request fetch.getJSON('https://api.example.com/data', { key: 'value' }) .then(result => console.log(result)) .catch(error => console.error(error)); // POST request fetch.postJSON('https://api.example.com/data', { name: 'test' }) .then(result => console.log(result)); // JSONP request (callback name can be set in options) fetch.getJSONP('https://api.example.com/jsonp', { q: 'test' }) .then(result => console.log(result));
Debug
Known issues
deprecatedPackage is unmaintained since 2018; last version 1.2.8 uses whatwg-fetch 2.x which is outdated.
fix
Consider switching to native fetch (if supported) or a maintained polyfill/helper like ky or unfetch.
affects: >=1.0.0
brokenJSONP method getJSONP does not return a standard Fetch Response; it resolves with the parsed JSON data from the callback.
fix
Do not expect .json() or .text() methods; the promise resolves directly with the response body.
affects: >=1.0.0
gotchaThe default mode is 'same-origin' which may block cross-origin requests unless CORS is configured.
fix
Set mode to 'cors' in options to allow cross-origin requests.
affects: >=1.0.0
gotchaGlobal options are mutated; setting fetch.globalOption.timeout = 5000 will affect all subsequent requests.
fix
Be aware that global options are merged with per-request options; use per-request options to override.
affects: >=1.0.0
deprecatedThe package depends on whatwg-fetch which has known CORS issues in older browsers; no updates.
fix
Use native fetch or a more modern polyfill.
affects: >=1.0.0
Errors
Common errors & fixes
fetch is not a function
Attempting to destructure fetch from the module or using import incorrectly.
fix
Use import fetch from 'fetch-plugin' or const fetch = require('fetch-plugin'); do not destructure.
fetch.getJSON() is not a function
Using CommonJS with require and expecting named exports, but the default export is the fetch function itself with getJSON attached.
fix
Use const fetch = require('fetch-plugin'); then fetch.getJSON(...).
Upgrade
Version history
1.2.8latest on npm
Audit
Dependencies
whatwg-fetchrequiredfetch-plugin extends whatwg-fetch polyfill to provide fetch functionality; it is a direct dependency
Agent activity
4 hits · last 30 days
node
4
Resources
fetch-plugin — npm install fetch-plugin · libregistry