Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
fetchy-request
Advanced tools
A simple way to make simple http requests.
npm install --save fetchy-request
## Notice: if you are using a legacy node version
## which does not contain a native Promise,
## please install and use a polyfill by yourself.
# npm install --save bluebird
In general, the API is pretty much a mixture of the fetch API and the popular request package.
A simple GET:
let request = require('fetchy-request')
request('http://open.meituan.com/cool-api/?k1=v1&k2=v2')
.then(function (response) {
return response.json()
}).then(function (json) {
console.log('parsed json', json)
})
The same GET [1]:
let request = require('fetchy-request')
request({
uri: 'http://open.meituan.com/cool-api/'
method: 'GET',
qs: {
k1: 'v1',
k2: 'v2'
}
})
A simple POST:
let request = require('fetchy-request')
request({
uri: 'http://open.meituan.com/cool-api/'
method: 'POST',
form: {
username: 'admin',
password: 'hackmeifyoucan!'
}
})
Another POST:
let request = require('fetchy-request')
request({
uri: 'http://open.meituan.com/cool-api/'
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: '{"json is": "Great!"}'
})
qs
and form
is stringified by qs;
POST body
overwrites form
.
File uploads are not yet supported.
Set response timeout in millisecond.
let request = require('fetchy-request')
request({
uri: 'http://open.meituan.com/cool-api/?k1=v1&k2=v2'
timeout: 2000
})
Retry for any http 5xx server errors or local syscall errors:
let request = require('fetchy-request')
request({
uri: 'http://open.meituan.com/cool-api/?k1=v1&k2=v2'
retry: 2
})
Automatically use process.env.HTTP_PROXY
for http requests.
HTTP_PROXY='http://127.0.0.1:8888' node server.js
Notice: this is purposely designed for debugging. DO NOT use in production environments.
let request = require('fetchy-request')
request({
uri: 'http://open.meituan.com/poi/12345?k1=v1&k2=v2',
// .displayName will be used in errors' message,
// default to the `.uri` if omitted
displayName: 'open.meituan.com/poi',
// label is readable in any events callback
label: ['tag1', 'tag2']
})
request.on('beforeSend', function (requestOptions) {
})
request.on('success', function (incommingMsg, requestOptions) {
console.log(requestOptions.displayName, 'timing:', incommingMsg.timing.response - incommingMsg.timing.start)
// => open.meituan.com/poi timing: 200
console.log(requestOptions.label)
// => ['tag1', 'tag2']
})
request.on('failure', function (error, requestOptions) {
console.warn(error.message)
// => 502 Bad Gateway: open.meituan.com/poi
console.log(requestOptions.displayName, 'request failed after', err.timing.error - err.timing.start, 'ms')
// => open.meituan.com/poi request failed after 300 ms
console.log(requestOptions.label)
// => ['tag1', 'tag2']
})
let request = require('fetchy-request')
request('http://unstable.meituan.com/user.xml?user=xiaody')
.then(function (response) {
const fallback = { user: '', phone: '', error: true }
// request failed
if (!response.ok)
return fallback
// in case its not JSON
return response.safeJson(function (e) {
send_error_msg('error occurs when parse response as JSON:', e)
return fallback
// the error `e` will be returned if this error handler is omitted;
// you can also pass in the fallback as a second argument, which overwrite the return value of the error handler.
})
}).then(function (userInfoOrFallback) {
// use userInfo or fallback
})
_ [1] In fact, there is a little difference when they come to error reporting. _
FAQs
Request done right
We found that fetchy-request 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
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.