Giter Site home page Giter Site logo

superagent-use's Introduction

superagent-use Build Status

Global plugin support for SuperAgent.

Summary

Instead of manually calling use() for every request, use() is called automatically for every request.

Example

/* The superagent-use module returns a clone of the superagent provided with the new functionality. */
var agent = require('superagent-use')(require('superagent'));
/* A sample superagent plugin/middleware. */
var prefix = require('superagent-prefix');

agent.use(prefix('https://api.example.com'));

agent
  .post('/auth')
  .send({user: 'foo', pass: 'bar123'})
  .on('request', function(req) {
    console.log(req.url); // => https://api.example.com/auth
  })
  .end(function(err, res) {
    //
  });

superagent-use's People

Contributors

jonatanklosko avatar koenpunt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

superagent-use's Issues

Superagent dependency

Making this dependent on superagent makes it troublesome when updates come. I think it could be easily fixed by doing:

module.exports = function(_superagent) {
  // stuff
  return superagent;
};

And using it would be as follows:

const superagent = require('superagent');
superagent = require('superagent-use')(superagent);

This removes superagent dependency and just extends the user's one.
Is this repo alive? If so I can submit PR for this =)

TypeError: request.use is not a function

Running the example in the readme, I'm given the following error:

TypeError: request.use is not a function
    at /path/to/working_dir/node_modules/superagent-use/index.js:22:27
    at Array.forEach (native)
    at Object.superagent.(anonymous function) [as post] (/path/to/working_dir/node_modules/superagent-use/index.js:21:12)
    at repl:1:7
    at realRunInThisContextScript (vm.js:22:35)
    at sigintHandlersWrap (vm.js:98:12)
    at ContextifyScript.Script.runInThisContext (vm.js:24:12)
    at REPLServer.defaultEval (repl.js:346:29)
    at bound (domain.js:280:14)
    at REPLServer.runBound [as eval] (domain.js:293:12)

I'm using version 0.1.0.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.