Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

oniyi-http-client

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

oniyi-http-client

Adding a plugin interface to "request" that allows modifications of request parameters and response data.

  • 0.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
increased by200%
Maintainers
1
Weekly downloads
 
Created
Source

NPM version Dependency Status

Adding a plugin interface to "request" that allows modifications of request parameters and response data.

Why?

Working with the popular module request for your http requests is awesome. But sometimes you might need to go beyond the standard features.

Install

$ npm install --save oniyi-http-client

Usage

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
});

License

MIT © Benjamin Kroeger

Keywords

FAQs

Package last updated on 14 May 2015

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc