
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
$ npm install --save oniyi-http-client
Note: this module does not support streams, yet
var OniyiHttpClient = require('oniyi-http-client');
var client = new OniyiHttpClient({
defaults: {
headers: {
'Accept-Language': 'en-US,en;q=0.8',
Host: 'httpbin.org',
'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',
Accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'
}
}
});
client.makeRequest('http://httpbin.org/headers', {
method: 'GET'
// jar: client.jar(new redisStore(redisClient))
}, function (err, response, body) {
if (err) {
logger.warn('got an error');
if (err.stack) {
logger.error(err.stack);
} else {
logger.error(err);
}
process.exit(0);
}
if (response) {
logger.debug('statusCode: %d', response.statusCode);
logger.debug('headers: ', response.headers);
logger.debug('body: ', body);
}
process.exit(0);
});
This creates a plugin named plugin-2
which adds a request-header with name and value plugin-2
.
Also, it stores some data in a local variable and overrides the original callback function
to print that stored data on response. Afterwards it calls the original callback function.
var plugin2 = {
name: 'plugin-2',
load: function (req, params, callback) {
var plugin2Storage = {};
setTimeout(function () {
params.headers = params.headers || {};
params.headers['plugin-2'] = 'plugin-2';
var name = 'Bam Bam!';
var originalCallback = params.callback;
params.callback = function (err, response, body) {
logger.info('Name in this plugin\'s store: %s', name);
return originalCallback(err, response, body);
};
callback(null, params);
}, 500);
}
};
client
.use(plugin2)
.makeRequest('http://httpbin.org/headers', {
method: 'GET'
// jar: client.jar(new redisStore(redisClient))
}, function (err, response, body) {
if (err) {
logger.warn('got an error');
if (err.stack) {
logger.error(err.stack);
} else {
logger.error(err);
}
process.exit(0);
}
if (response) {
logger.debug('statusCode: %d', response.statusCode);
logger.debug('headers: ', response.headers);
logger.debug('body: ', body);
}
process.exit(0);
});
Apache-2.0 © 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.