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 fetchivalNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates basic CRUD operations using fetchival with JSONPlaceholder API.
Always attach a .catch() to handle HTTP errors.
Add fetchival.fetch = require('node-fetch'); at the top of your Node script.Consider using ky or plain fetch with a wrapper for modern projects.
For modern environments, you may omit polyfills.
Use `import fetchival from 'fetchival'` for ESM or `const fetchival = require('fetchival').default` if using CommonJS.Always create an instance: const api = fetchival('/posts'); then api.get()In Node: install node-fetch and assign fetchival.fetch = require('node-fetch'). In browser: include whatwg-fetch polyfill.Pass { responseAs: 'text' } as fetchOptions to fetchival() to handle plain text.