Unfetch is a very small JavaScript library, roughly 500 bytes when compressed, that adds the ability to make web requests in older browsers that do not support the modern fetch() function. When a web page needs to load data from a server without refreshing the whole page, it typically calls fetch(). Unfetch provides that same calling style for browsers that would otherwise throw an error. The library can be used in two ways. The first is as a polyfill, meaning it quietly replaces the missing fetch() function in the browser so that existing code just works without any changes. The second is as a ponyfill, meaning you import it explicitly in your code and call it directly, without touching any global browser state. The ponyfill approach is useful when you want to be explicit about which function you are calling regardless of what the browser provides. Unfetch covers the basics: sending GET and POST requests, passing custom headers, including cookies via the credentials option, and reading the response as text, JSON, or a binary blob. It does not support streaming responses, and its Headers and Response objects are simplified versions of the full specification. The README is explicit about what is missing so developers know what they are getting. Two important behaviors differ from what some developers expect coming from older libraries like jQuery. By default, unfetch does not send or receive cookies unless you pass credentials: 'include'. Also, a failed HTTP status like a 404 or 500 does not cause the returned Promise to reject automatically. The promise only rejects on a network-level failure. Developers who want HTTP errors to behave as errors need to check response.ok themselves and throw accordingly. The package is published to npm and can also be dropped into a page directly from a CDN link. For use in Node.js rather than a browser, a companion package called isomorphic-unfetch is available from the same author.
← developit on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.