
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
oniyi-http-client
Advanced tools
Adding a plugin interface to "request" that allows modifications of request parameters and response data.
Adding a plugin interface to "request" that allows modifications of request parameters and response data.
Working with the popular module request for your http requests is awesome. But sometimes you might need to go beyond the standard features.
$ npm install --save oniyi-http-client
var tough = require('tough-cookie');
var OniyiHttpClient = require('oniyi-http-client');
var client = new OniyiHttpClient();
client.registerPlugin('async-cookie-jar')
// a plugin that only adds a request header and returns the params object synchronusly
.registerPlugin({
name: 'plugin-1',
onRequest: function(params) {
params.headers = params.headers || {};
params.headers.foo = 'bar';
return params;
}
})
// this plugin wwill add a header and store some data in it's own storage
// setTimeout is used to simulate async callback of the params object
.registerPlugin({
name: 'plugin-2',
storesData: true, // this has to be set to true if the plugin wants to use a storage
onRequest: function(params, store, callback) {
setTimeout(function() {
params.headers = params.headers || {};
params.headers['plugin-2'] = 'plugin-2';
store.name = 'Bam Bam!';
callback(null, params);
}, 500);
},
// in callback, this plugin has access to it's storage again
callback: function(next, store, err, response, body) {
console.log('Name in this plugin\'s store: %s', store.name);
// pass arguments on to the next plugin
next.call(this, err, response, body);
}
});
client.makeRequest('https://www.npmjs.com', {
jar: new tough.CookieJar(asyncStore)
}, function(err, response, body){
// do your normal response handling here
});
MIT © Benjamin Kroeger
FAQs
Adding a plugin interface to "request" that allows modifications of request parameters and response data
The npm package oniyi-http-client receives a total of 1 weekly downloads. As such, oniyi-http-client popularity was classified as not popular.
We found that oniyi-http-client 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
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.