isomorphic-fetch
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
node-fetch | 2.7.0 | 43.6 kB | MIT | prod | |
whatwg-fetch | 3.6.20 | 13.15 kB | MIT | prod |
Isomorphic-Fetch is a library that enables the use of the Fetch API in a node environment and ensures its functionality is consistent between the client and the server. By leveraging GitHub's WHATWG Fetch polyfill, it allows developers to use fetch
in their Node.js code in a cross-browser compliant manner, mitigating the inconsistencies found in browser implementations of the Fetch API.
To start using Isomorphic-Fetch in your project, you need to install the package. If you are using npm as your package manager, the installation command is npm install --save isomorphic-fetch
. For Bower users, the command is bower install --save isomorphic-fetch
.
Once installed, the Fetch API can be invoked in your code by requiring the isomorphic-fetch
module at the top of your JavaScript file:
require('isomorphic-fetch');
fetch('http://example.com/some-api-endpoint')
.then(function(response) {
if (response.status >= 400) {
throw new Error("Bad response from server");
}
return response.json();
})
.then(function(data) {
console.log(data);
});
In this example, we use the fetch function to make a request to 'http://example.com/some-api-endpoint'. If the response status is 400 or above, it throws an error. Otherwise, it converts the received data to a JSON object and logs it to the console.
The documentation for Isomorphic-Fetch can be found on its GitHub repository, at https://github.com/matthew-andrews/isomorphic-fetch
. It offers detailed information on installation, usage, licensing and alternatives. The examples of using fetch with different APIs are also provided to guide new users. Be sure to check out the repository's readme file for a quick guide to getting started with isomorphic-fetch
.