
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.
Beautifully RESTful.
npm install restiful --save
Cumbersome fetch:
// POST /users
fetch('/users', {
method: 'post',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: 'admin',
login: 'password',
}),
}).then(function(response) {
if (response.status >= 200 && response.status < 300) {
return response.json();
}
throw new Error(response.statusText);
}).then(function(json) {
// ...
});
restiful equivalent:
// POST /users
restiful('/users').post({
name: 'admin',
login: 'password'
}).then(function(json) {
// ...
});
.get(), .put(), .patch() and .delete() methods are also available.
Supports both Node and browser environments. Makes use of node-fetch v2 for Node environments.
For the sake of real estate, node-fetch is externalized; therefore, must be installed separately.
import restiful from 'restiful';
var blog = restiful('/blog');
/* /blog/posts */
var posts = blog('posts');
posts.get();
posts.post({
title: 'restiful',
});
/* /blog/posts?category=javascript */
posts.get({
category: 'javascript',
});
/* /blog/posts/1 */
var firstPost = posts(1);
firstPost.get();
firstPost.put({ title: 'restiful is simple' });
firstPost.patch({ title: 'restiful is simple' });
firstPost.delete();
var firstPostComments = firstPost('1/comments');
/* /blog/posts/1/comments */
firstPostComments.get();
/* /blog/posts/1/comments/1 */
firstPostComments(1).get();
Easily converts to string:
String(restiful('/blog/posts')) // "/blog/posts"
To catch errors:
restiful('/posts')
.get()
.catch(function(err) {
console.log(err);
});
You can also pass fetch options to restiful:
var posts = restiful('/blog/posts', fetchOptions);
var comments = posts('1/comments'); // Will inherit fetchOptions
Standard fetch options (e.g. enabling CORS):
var request = restiful('/', { mode: 'cors' });
var posts = request('posts');
Non-standard fetch options (e.g. changing response type):
var request = restiful('/', { responseAs: 'text' });
var posts = request('posts');
responseAs can be response (for full response), blob, text or json (default).
FAQs
RESTful APIs simplified
We found that restiful 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.