
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.
@jontetz/jfetch
Advanced tools
Using npm:
$ npm i @jontetz/jfetch
import jfetch from '@jontetz/jfetch';
Performing a GET request
// Make a request for a user with a given ID
jfetch.get('/user?ID=12345')
.then(response => {
// handle success
console.log(response);
})
.catch(error => {
// handle error
console.log(error);
})
.finally(() => {
// always executed
});
// Optionally the request above could also be done as
jfetch.get('/user', {
ID: 12345
})
.then(response => {
console.log(response);
})
.catch(error => {
console.log(error);
})
.finally(() => {
// always executed
});
// Want to use async/await? Add the `async` keyword to your outer function/method.
async function getUser() {
try {
const response = await jfetch.get('/user?ID=12345');
console.log(response);
} catch (error) {
console.error(error);
}
}
Performing a POST request
// Make a request to create a new user
jfetch.post('/user', {
name: 'John Smith'
})
.then(response => {
// handle success
console.log(response);
})
.catch(error => {
// handle error
console.log(error);
})
.finally(() => {
// always executed
});
Performing a PUT request
// Make a request to update a users name
jfetch.put('/user/123', {
name: 'John Smith'
})
.then(response => {
// handle success
console.log(response);
})
.catch(error => {
// handle error
console.log(error);
})
.finally(() => {
// always executed
});
Performing a DELETE request
// Make a request for a user with a given ID
jfetch.del('/user/1234/delete')
.then(response => {
// handle success
console.log(response);
})
.catch(error => {
// handle error
console.log(error);
})
.finally(() => {
// always executed
});
// Optionally the request above could also be done as
jfetch.del('/user', {
ID: 12345
})
.then(response => {
// handle success
console.log(response);
})
.catch(error => {
// handle error
console.log(error);
})
.finally(() => {
// always executed
});
Aborting a request
// store a reference to the original promise
const request = jfetch.get('/user');
request.then(response => {
// handle success
console.log(response);
})
.catch(error => {
// handle an abort error
if(error === 'AbortError') return;
// handle error
console.log(error);
});
// abort the request
request.controller.abort();
You can modify the fetch itself by passing an object to the third parameter
jfetch.post('/user/12345', {
ID: 12345
}, {
responseType: 'text', // json, text or blob - this option is specific to jfetch
credentials: 'none', // this removes the default 'include' that is included in each request
headers: {
'Content-Type': 'application/json'
}
})
.then(response => {
console.log(response);
})
.catch(error => {
console.log(error);
})
.finally(() => {
// always executed
});
credentials: 'include' is included in the requests by default to send cookie data. To remove that setting, you can pass credentials: 'none' in the third parameter.
Set some default headers that should be in each request
Or set the base url that should be prepended to each request
import jfetch from '@jontetz/jfetch';
jfetch.defaults.headers['Content-Type'] = 'application/json';
jfetch.defaults.baseUrl = '/test';
FAQs
A tiny fetch wrapper built for the browser
We found that @jontetz/jfetch 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.