
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.
A simple promise based http client which rejects the promise when the status ode is not 200 - OK
A simple promise based http client which rejects the promise when the status is not 200 - OK
Instead of having if-statements to check the http status code when a request returns, http-ok rejects the promise when the status code is not as expected (by default 200). This should make the promise chain look much simpler and more focused on the succes flow.
const HttpOk = require("http-ok")
const client = new HttpOk();
client.get('www.google.com')
.then(response => {
/// process here the response
})
.catch(error => {
/// error handling here
}
});
const fetch = require("node-fetch");
fetch('www.google.com')
.then(response => {
if(response.statusCode === 200) {
/// process here the response
} else {
// error handling here
}
}
).catch(err => {
// error handling here
});
node http API. Uses the same request options object.npm install http-ok --save
const HttpOk = require('http-ok');
const client = new HttpOk();
client.get('https://github.com/')
.then(res => res.text())
.then(bodyText => console.log(bodyText))
.catch(err => console.log(err));
client.get('https://api.github.com/users/github')
.then(res => res.json())
.then(json => console.log(json))
.catch(err => console.log(err));
const querystring = require('querystring');
const formData = {
name: 'Bob Mc Bobson',
place: 'Cheddar'
};
const postData = querystring.stringify(formData);
const requestOptions = {
hostname: 'http://httpbin.org',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': Buffer.byteLength(postData)
}
};
client.post(requestOptions, postData, 200)
.then(res => {
// process here the response
}).catch(json => {
// error handling here
});
client.get('http://redirected.com', 302)
.then(response => {
// process here the response
}).catch(error => {
// error handling here
});
See test cases for more examples.
get(url) // default 200
get(url, expectedStatusCode)
get(options, expectedStatusCode)
post(url, postData) // default 200
post(url, postData, expectedStatusCode)
post(options, postData, expectedStatusCode)
Returns a Promise
Should be an absolute url, eg http://example.com
same as node.js http.request options.
and integer eg 200 or 301
url encoded string
MIT
FAQs
A simple promise based http client which rejects the promise when the status ode is not 200 - OK
We found that http-ok 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.