Miss any of our Open RFC calls?Watch the recordings here! »

subrequests-express

1.10.1 • Public • Published

Subrequests Express

Coverage Status Known Vulnerabilities semantic-release Commitizen friendly Greenkeeper badge Build Status

Usage

On the Express Server

To support subrequests in your express server you only need to add it to your router.

// app.js
const { SubrequestsRouter } = require('subrequests-express');
 
// All your route declarations.
// …
 
// Add the request aggregator.
router.use(SubrequestsRouter);

This will add a route in /subrequests that will process blueprints either by GET or POST requests.

Customize the Route

In order to customize the route of the request aggregator you will need to add it to your configuration object using config.

Set the route in the configuration json/yaml for your environment.

subrequests:
  route: '/:version/my-request-aggregator'

That will accept requests to https://example.org/^v5.0.1/my-request-aggregator, for instance. Note that you can include parameters that Express will process normally.

Customize the Response Format

You can provide a subresponse merged plugin by attaching it to the express request object under the subrequestsResponseMerge key. You can do something like:

// app.js
const { SubrequestsRouter } = require('subrequests-express');
const JsonResponse = require('subrequests-json-merger');
 
// All your route declarations.
// …
 
router.all(config.get('subrequests.route'), (req, res, next) => {
  // Make sure that subrequests-json-merger merges responses using JSON.
  req.subrequestsResponseMerger = JsonResponse;
  next();
});
// Request aggregator.
router.use(SubrequestsRouter);
 

On the Consumer Application

Use the request aggregator normally under /subrequests or the configured route. See Subrequests for more information on how to use Subrequests.

Install

npm i [email protected]

Version

1.10.1

License

GPL-2.0

Last publish

Collaborators

  • avatar