fetchival.js
Note: This is fork of typicode/fetchival
with pluggable registry of response handler functions and data encoding functions,
as well as a few bugfixes. yarn add fetchival-pluggable
Makes writing JSON requests with fetch easier
Fetchival is a tiny (0.7KB min/gz) fetch wrapper that can be used in the browser (IE9+) and Node.
Before
// POST /users
After
// POST /users
.get()
, .put()
, .patch()
and .delete()
methods are also available.
Installation
Fetchival is available on Bower and npm
Browser
bower install es6-promise fetch # polyfills bower install fetchival
npm install es6-promise whatwg-fetch --save # polyfills npm install fetchival --save # Browserify
Node
npm install node-fetch fetchival --save
Usage examples
var posts = //postspostsposts //posts?category=javascriptposts //posts/1 var comments = //posts/1/commentscomments //posts/1/comments/1
You can also pass fetch options to fetchival()
var posts = var comments = // Will inherit fetchOptions
To catch errors
To enable CORS
var request = var posts =
To fetch plain text (for example, HTML views)
var request = var posts =
responseAs
can be response
, text
or json
(default)
To use fetchival in Node, you need to install node-fetch
and configure fetchival to use it
var fetchival = fetchivalfetch =
Browser Support
Latest ✔ | Latest ✔ | 9+ ✔ | Latest ✔ | 6.1+ ✔ |
License
MIT - Typicode