
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
Make the `fetch` API great again! This library is a very simple interface on top of the `fetch` API - so that you don't need to parse stuff or deal with issues.
Make the fetch API great again! This library is a very simple interface on
top of the fetch API - so that you don't need to parse stuff or deal with
issues.
This library doesn't include a polyfill - if you need one, make sure to
import it as well!
isomorphic-fetch is a
great alternative.
First, install it:
$ yarn add fetchutils # or npm install --save fetchutils
Then, use it!
import { get, post, put, del } from 'fetchutils';
function getUsers() {
return get('/api/users');
}
function saveUser(user) {
return post('/api/users', user);
}
function updateUser(user), {
return put(`/api/users/${user.id}`, user);
}
function deleteUser(user) {
return del(`/api/users/${user.id}`);
}
Each of the methods returns a promise, with the first argument being the parsed result (either text or JSON, based on content type). The method will throw if the response code is >= 400, also then with the parsed result.
The error thrown is of the type FetchError, with the following properties:
{
message, // The status code description
status, // The status code
details, // The parsed response from the server
}
You can send data with your request as the second argument to each function.
If the method is get, the argument will be turned into get-parameters.
Otherwise, the second argument is run through JSON.stringify() and sent as
the body.
import { get, post } from 'fetchutils';
// Produces a get-request for /api/users?search=stuff&limit=10
function searchUsers(query, limit = 10) {
return get('/api/users', { search: query, limit });
}
// Produces a post-request with {"name": "Scott", "age": 42} as a body
function addUser(name, age) {
return post('/api/users', { name, age });
}
Yep, this is pretty opinionated. So if you want to override or add headers,
or send some more parameters to the fetch function - send all of those in as
a third parameter. Here's an example:
import { get } from 'fetchutils';
function getUsersFromMyApp() {
return get('http://www.some-api.io/api/users', {
headers: { 'X-Requested-By': 'my-application' },
mode: 'cors',
});
}
This library is small on purpose. If you need a feature I haven't thought of, create a new issue, and - if you're cool - submit a pull request.
FAQs
Make the `fetch` API great again! This library is a very simple interface on top of the `fetch` API - so that you don't need to parse stuff or deal with issues.
We found that fetchutils demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.