SuperAgent

Ajax for Node.js and browsers (JS HTTP client). Maintained for @forwardemai...

README

superagent


build status
code coverage
code style
styled with prettier
made with lass
license

Small progressive client-side HTTP request library, and Node.js module with the same API, supporting many high-level HTTP client features. Maintained for Forward Email and Lad.



Table of Contents


  Node


Install


[npm][]:

  1. ```sh
  2. npm install superagent
  3. ```

[yarn][]:

  1. ```sh
  2. yarn add superagent
  3. ```


Usage


Node


  1. ```js
  2. const superagent = require('superagent');

  3. // callback
  4. superagent
  5.   .post('/api/pet')
  6.   .send({ name: 'Manny', species: 'cat' }) // sends a JSON post body
  7.   .set('X-API-Key', 'foobar')
  8.   .set('accept', 'json')
  9.   .end((err, res) => {
  10.     // Calling the end function will send the request
  11.   });

  12. // promise with then/catch
  13. superagent.post('/api/pet').then(console.log).catch(console.error);

  14. // promise with async/await
  15. (async () => {
  16.   try {
  17.     const res = await superagent.post('/api/pet');
  18.     console.log(res);
  19.   } catch (err) {
  20.     console.error(err);
  21.   }
  22. })();
  23. ```

Browser


The browser-ready, minified version of superagent is only 50 KB (minified and gzipped).

Browser-ready versions of this module are available via [jsdelivr][], [unpkg][], and also in the node_modules/superagent/dist folder in downloads of the superagent package.

Note that we also provide unminified versions with .js instead of .min.js file extensions.


VanillaJS


This is the solution for you if you're just using `