Registry / testing / fetchival

fetchival

JSON →
library0.3.3jsnpmunverified

A tiny (0.5kb min/gz) fetch wrapper for making JSON requests easier in the browser (IE9+) and Node. Current stable version is 0.3.3. It simplifies common fetch patterns by providing .get(), .post(), .put(), .patch(), and .delete() methods with automatic JSON handling, headers, and error checking. Unlike plain fetch, it automatically serializes request bodies to JSON, parses responses, and rejects non-2xx status codes. It also supports path nesting (e.g., fetchival('/posts')(1).get()). Requires a fetch polyfill in older browsers (whatwg-fetch) and a fetch implementation in Node (node-fetch). Low release cadence (last update 2015).

npm install fetchival
INSTALL
IMPORT
SIG · FETCHIVAL
F
fetchival
testingjavascriptv0.3.3
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.

fetchival
import fetchival from 'fetchival'
const fetchival = require('fetchival')
Package exports a default function. Use ESM import for bundlers; in CommonJS you must require the module as shown, but it's not a default export from ESM perspective – actually require works too.
fetchival.fetch
fetchival.fetch = require('node-fetch')
import { fetch } from 'fetchival'
For Node.js usage, you must assign node-fetch to fetchival.fetch. There is no named export for fetch.
get
fetchival('/posts').get()
fetchival.get('/posts')
Methods are instance methods, not static. You must call fetchival with a URL first.

Demonstrates basic CRUD operations using fetchival with JSONPlaceholder API.

import fetchival from 'fetchival'; // Assuming fetch is polyfilled (browser) or node-fetch assigned (Node) // For Node: fetchival.fetch = require('node-fetch'); const posts = fetchival('https://jsonplaceholder.typicode.com/posts'); // GET /posts posts.get() .then(data => console.log('GET:', data)) .catch(err => console.error(err)); // POST /posts posts.post({ title: 'foo', body: 'bar', userId: 1 }) .then(data => console.log('POST:', data)); // GET /posts/1 posts(1).get() .then(data => console.log('GET /posts/1:', data)); // PUT /posts/1 posts(1).put({ id: 1, title: 'updated', body: 'bar', userId: 1 }) .then(data => console.log('PUT:', data)); // PATCH /posts/1 posts(1).patch({ title: 'patched' }) .then(data => console.log('PATCH:', data)); // DELETE /posts/1 posts(1).delete() .then(() => console.log('DELETE successful'));
Debug
Known issues
gotchafetchival does not throw on non-2xx status codes; it rejects the promise. Ensure you handle errors with .catch().
fix
Always attach a .catch() to handle HTTP errors.
affects: >=0.0.0
gotchaIn Node, you must manually assign fetchival.fetch = require('node-fetch') before using fetchival.
fix
Add fetchival.fetch = require('node-fetch'); at the top of your Node script.
affects: >=0.0.0
gotchaThe package is not actively maintained; last release in 2015. Do not expect updates or security patches.
fix
Consider using ky or plain fetch with a wrapper for modern projects.
affects: >=0.0.0
deprecatedThe package uses older patterns like es6-promise polyfill. Modern browsers have native fetch and Promise support.
fix
For modern environments, you may omit polyfills.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: fetchival is not a function
CommonJS require returns an object, not a function. The import style may be wrong.
fix
Use `import fetchival from 'fetchival'` for ESM or `const fetchival = require('fetchival').default` if using CommonJS.
Uncaught TypeError: Cannot read property 'then' of undefined
Calling .get() without invoking fetchival first, e.g., fetchival.get('/posts') instead of fetchival('/posts').get()
fix
Always create an instance: const api = fetchival('/posts'); then api.get()
ReferenceError: fetch is not defined
fetch is not available in Node environment or older browser without polyfill.
fix
In Node: install node-fetch and assign fetchival.fetch = require('node-fetch'). In browser: include whatwg-fetch polyfill.
Uncaught (in promise) Error: Invalid JSON response
fetchival expects JSON response by default, but server returned non-JSON (e.g., HTML).
fix
Pass { responseAs: 'text' } as fetchOptions to fetchival() to handle plain text.
Upgrade
Version history
0.3.3latest on npm
Audit
Dependencies
whatwg-fetchoptionalRequired in browsers that don't support fetch natively (IE9+).
es6-promiseoptionalRequired in browsers that don't support Promises (IE9+).
node-fetchoptionalRequired in Node.js environment to provide fetch implementation.
Agent activity
2 hits · last 30 days
node
2
Resources
fetchival — npm install fetchival · libregistry