
Security News
Microsoft Releases Open Source Toolkit for AI Agent Runtime Security
Microsoft has released an open source toolkit for enforcing runtime security policies on AI agents as adoption accelerates faster than governance controls.
Simple HTTP client with failover functionality for node.js and browsers
It supports simple fallback addresses as well as dynamic service discovery using Consul.
Multiagent uses superagent under the covers and exposes most of its API as well as an additional promise interface (if native promises are available).
All browsers with ECMAScript 5 support should work.
node.js, browserify, webpack:
npm install --save multiagent
as a global script in the browser:
<script src="node_modules/multiagent/lib/browser.min.js"></script>
from a CDN:
<script src="https://npmcdn.com/multiagent/lib/browser.min.js"></script>
In case you load multiagent with a script reference into the browser,
it will create the global variable multiagent.
Multiagent can be used as a simple HTTP client, pretty much as a drop-in replacement of superagent:
const agent = require('multiagent');
// create a request:
const req = agent.request('GET', 'http://domain.com');
// or use a shorthand (there's also: 'head', 'post', 'put', 'delete'/'del')
const req = agent.get('http://domain.com');
// execute a request, providing a callback:
req.end((err, res) => console.log(err || res.body));
// or instead, use the promise interface:
const promise = req.promise();
promise.then(res => console.log(res.body), err => console.log(err));
// you can also simply just call 'then' (or 'catch') on the request:
req.then(res => console.log(res.body), err => console.log(err));
If you have your service running on multiple endpoints, you can provide a list of hard-coded server URLs and take advantage of multiagent's failover mechanism:
const agent = require('multiagent');
// create a client:
const client = agent.client({
servers: ['http://sub1.abc.com', 'http://sub2.abc.com', 'http://sub3.abc.com']
});
// then do stuff:
client
.get('/endpoint') // use just the path without host!
.timeout(500) // used per individual call!
.end((err, res) => console.log(err || res.body));
Instead of hard-coding your server URLs you can use a Consul server or cluster to dynamically resolve the base URLs for your service calls:
const agent = require('multiagent');
// create a client:
const client = agent.client({
discovery: 'consul', // only possible value at the moment, more could be added in the future
discoveryServers: ['http://consul1.abc.com', 'http://consul2.abc.com', 'http://consul3.abc.com'],
serviceName: 'my-service'
});
// then do stuff:
client
.get('/endpoint') // use just the path without host!
.timeout(500) // used per individual service call!
.end((err, res) => console.log(err || res.body));
If you're just interested in the service URLs e.g. from Consul without actually calling any
service endpoint, you can use the resolveServers function provided by the client instance:
const agent = require('multiagent');
// create a client:
const client = agent.client({
discovery: 'consul',
discoveryServers: ['http://consul1.abc.com', 'http://consul2.abc.com', 'http://consul3.abc.com'],
serviceName: 'my-service'
});
// get the list of servers providing a callback:
client.resolveServers((err, servers) => console.log(err || servers));
// or use the promise interface:
client.resolveServers().then(servers => console.log(servers));
For the client using simple failover you can pass the following additional options:
(err, res) => err || res.status >= 400For the client using Consul you can pass the following additional options:
(err, res) => err || res.status >= 400serviceName => `/v1/health/service/${encodeURIComponent(serviceName)}?passing=true` ,(body, serviceProtocol) => body.map(x => `${serviceProtocol}://${x.Service.Address}:${x.Service.Port}`)When you create a client with failover using agent.client({ /* options */ }) you can override
the failover strategy as well as the failover criteria on a per request basis. This is sometimes useful
when e.g. in a RESTful environment a response with status code 404 (not found) is a perfectly valid
result and should not lead to any failover:
// create a client with default options for all requests issued using this client instance:
const client = agent.client({
servers: ['http://sub1.abc.com', 'http://sub2.abc.com', 'http://sub3.abc.com'],
strategy: 'simultaneously',
shouldFailover: (err, res) => err || res.status >= 400
});
// this will execute the requests sequentially and NOT failover on a 404 status response,
// thus overriding the options 'strategy' and 'shouldFailover' set as default on the client:
client
.get('/endpoint')
.failover({ strategy: 'sequentially' })
.failover({ shouldFailover: (err, res) => err || (res.status >= 400 && res.status !== 404) })
The following functions from superagent are supported:
Additionally:
Additionally:
MIT
FAQs
Simple HTTP client with failover functionality for node.js and browsers
We found that multiagent demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Microsoft has released an open source toolkit for enforcing runtime security policies on AI agents as adoption accelerates faster than governance controls.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.