gitmyhub

superagent

JavaScript ★ 17k updated 5mo ago

Ajax for Node.js and browsers (JS HTTP client). Maintained for @forwardemail, @ladjs, @spamscanner, @breejs, @cabinjs, and @lassjs.

A lightweight JavaScript library for making HTTP requests that works in both Node.js and browsers with a friendly chained API, supporting callbacks, promises, and async/await from a single install.

JavaScriptNode.jssetup: easycomplexity 2/5

SuperAgent is a small library that helps JavaScript code make HTTP requests, which is how programs talk to web servers to fetch data, submit forms, send JSON, upload files, and so on. It works in two environments from a single, consistent interface: inside Node.js (server-side JavaScript) and inside web browsers. The browser-ready bundle is around 50 KB once minified and compressed.

You write requests in a chained style: pick the HTTP verb you want (get, post, put, delete), set headers, attach a JSON body, add query parameters, and then either pass a callback or await the result like a promise. The same code works with old-style callbacks, .then/.catch promises, or modern async/await syntax, so it fits whatever pattern a project is already using. In the browser it can be loaded with a plain script tag from common CDNs (jsdelivr or unpkg), or imported through a bundler such as browserify, webpack, or rollup. On the server it installs from npm or yarn.

The library is extensible through plugins, which attach to a request with a .use() call and can do things like prevent caching, prefix URLs, mock out responses for tests, throttle requests, sign AWS requests, measure timings, or convert response payloads into different shapes. A long list of community plugins is included in the README.

Someone would reach for SuperAgent when they want a single HTTP client with a friendly chained API that works the same in Node.js and the browser, rather than mixing browser fetch with a separate server-side library. It supports Node 14.18 and up, and a wide range of modern browser versions, with a recommended polyfill for older browsers lacking WeakRef or BigInt. The full README is longer than what was provided.

Where it fits