SuperAgent is a small progressive client-side HTTP request library, and Node.js module with the same API, sporting many high-level HTTP client features. View the docs.
node:
$ npm install superagent component:
$ component install visionmedia/superagent Works with browserify and should work with webpack
request.post('/api/pet').send({name: 'Manny',species: 'cat'}).set('X-API-Key','foobar').set('Accept','application/json').end(function(err,res){// Calling the end function will send the request});Tested browsers:
- Latest Android
- Latest Firefox
- Latest Chrome
- IE9 through latest
- Latest iPhone
- Latest Safari
Even though IE9 is supported, a polyfill window.btoa is needed to use basic auth.
Superagent is easily extended via plugins.
varnocache=require('superagent-no-cache');varrequest=require('superagent');varprefix=require('superagent-prefix')('/static');request.get('/some-url').use(prefix)// Prefixes *only* this request.use(nocache)// Prevents caching of *only* this request.end(function(err,res){// Do something});Existing plugins:
- superagent-no-cache - prevents caching by including Cache-Control header
- superagent-prefix - prefixes absolute URLs (useful in test environment)
- superagent-suffix - suffix URLs with a given path
- superagent-mock - simulate HTTP calls by returning data fixtures based on the requested URL
- superagent-mocker — simulate REST API
- superagent-cache - superagent with built-in, flexible caching
- superagent-jsonapify - A lightweight json-api client addon for superagent
- superagent-serializer - Converts server payload into different cases
- superagent-promise-plugin - Shims req.end to return a promise when executed with no callback.
- superagent-use - A client addon to apply plugins to all requests.
- superagent-httpbackend - stub out requests using AngularJS' $httpBackend syntax
Please prefix your plugin with superagent-* so that it can easily be found by others.
For superagent extensions such as couchdb and oauth visit the wiki.
Install dependencies:
$ npm installRun em!
$ make testInstall dependencies:
$ npm installStart the test runner:
$ make test-browser-localVisit http://localhost:4000/__zuul in your browser.
Edit tests and refresh your browser. You do not have to restart the test runner.
MIT
