superagent
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
component-emitter | 1.3.1 | 2.46 kB | MIT | prod | |
cookiejar | 2.1.4 | 4.05 kB | MIT | prod | |
debug | 4.3.4 | 12.94 kB | MIT | prod | |
fast-safe-stringify | 2.1.1 | 7.71 kB | MIT | prod | |
form-data | 4.0.0 | 10.24 kB | MIT | prod | |
formidable | 2.1.2 | 25.44 kB | MIT | prod | 1 |
methods | 1.1.2 | 2.42 kB | MIT | prod | |
mime | 2.6.0 | 18.29 kB | MIT | prod | |
qs | 6.12.1 | 241.26 kB | BSD-3-Clause | prod | |
semver | 7.6.0 | 26.57 kB | ISC | prod |
Superagent is a small, progressive client-side HTTP request library. It also functions as a Node.js module with the same API, supporting many high-level HTTP client features. This respected library, maintained by Forward Email and Lad, is well-known for its feature-rich browser and node HTTP capacities combined with a fluent API. Its programming purpose is to enable an easier way of writing, reading and maintaining API requests in your code.
To utilize the power of Superagent in your project, the npm package must first be installed. By using commands npm install superagent
or yarn add superagent
, you are set to start with HTTP requests. Here are a few code examples showcasing its usage in Node.js and in the browser:
Node.js:
const superagent = require('superagent');
// callback
superagent
.post('/api/pet')
.send({ name: 'Manny', species: 'cat' }) // sends a JSON post body
.set('X-API-Key', 'foobar')
.set('accept', 'json')
.end((err, res) => {
// Calling the end function will send the request
});
// promise with then/catch
superagent.post('/api/pet').then(console.log).catch(console.error);
// promise with async/await
(async () => {
try {
const res = await superagent.post('/api/pet');
console.log(res);
} catch (err) {
console.error(err);
}
})();
Browser:
<script src="https://polyfill.io/v3/polyfill.min.js?features=WeakRef,BigInt"></script>
<script src="https://cdn.jsdelivr.net/npm/superagent"></script>
<script type="text/javascript">
(function() {
superagent
.post('/api/pet')
.send({ name: 'Manny', species: 'cat' }) // sends a JSON post body
.set('X-API-Key', 'foobar')
.set('accept', 'json')
.end(function (err, res) {
// Calling the end function will send the request
});
})();
</script>
The Superagent library has a comprehensive documentation available directly on their GitHub page (https://github.com/ladjs/superagent). The readme document presents install instructions, usage examples for both Node.js and browser configurations, descriptions of supported platforms, and a list of noteworthy plugins. Users planning to upgrade from previous versions of the Superagent library will also find an upgrading guide in the readme section.