Fetch/Off.js is a Fetch API polyfill and facade for Node.js. That is, it allows you to use the Fetch interface you might be familiar with in the browser to make web requests from Node.js, getting back either a Fetch compatible
Response object or Node.js's own
IncomingMessage (like you would from vanilla
Http.get()). In the latter respect it's a unique polyfill library — you have an option to use Fetch for requests, but still get the full streaming power of Node.js's responses.
Fetch/Off.js doesn't yet fully match the living Fetch API — it's missing redirect support for example — but for the common case it's sufficient.
npm install fetch-off
Fetch/Off.js follows semantic versioning, so feel free to depend on its major version with something like
>= 1.0.0 < 2 (a.k.a
Fetch Compatible Request and Response
By default requiring Fetch/Off.js will give you a Fetch compatible function that takes
options arguments and resolves with an equally compatible Fetch's
var fetch =var res =res
As with the Fetch API, pass
method to options to make POST requests:
var res =res
If you'd like to automate serializing objects to JSON or HTML forms, please see:
Those modules work perfectly with Fetch/Off.js's implementation.
Fetch Compatible Request with Node's Response
request file will give you a Fetch API compatible request function that takes
options arguments. It resolves with the vanilla Node's response object (
IncomingMessage) as you would get from
var request =var res =res
In that way it's a very lightweight alternative to Mikael's request module.
Fetch Compatible Response with Node's Request
If you have some code or middleware that works only with Fetch API
Response objects, yet you make requests yourself, pass the Node.js's
IncomingMessage object to FetchOff's
var Http =var Response =var res = Httpres
Fetch/Off.js is released under a Lesser GNU Affero General Public License, which in summary means:
- You can use this program for no cost.
- You can use this program for both personal and commercial reasons.
- You do not have to share your own program's code which uses this program.
- You have to share modifications (e.g. bug-fixes) you've made to this program.
For more convoluted language, see the