1.13.0 • Published 6 years ago

subrequests-json-merger v1.13.0

Weekly downloads
12,329
License
GPL-2.0
Repository
github
Last release
6 years ago

Subrequests JSON Merger

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

This module allow you to alter the format of the single response you get from Subrequests. Instead of merging the sub-responses into a multipart/related HTTP response, using this module we can merge them into a JSON object.

This JSON object will be keyed by request ID (possible expanded because of JSONPath queries). Each top-level value is an object itself. Such objects contain the headers and the body of the response.

Usage

Inject the merger into subrequests when making a request.

const JsonReponse = require('subrequests-json-merger');

subrequests.request(
  blueprint,
  new HttpRequestor(),
  JsonReponse // Make Subrequests produce a JSON document with all the responses.
)
.then(singleResponse => doYourStuff(singleResponse));

Using the example in the Subrequests module you will get the following output:

{
  "req1": {
    "headers": {
      "content-length": "23",
      "…": "…",
      "x-subrequest-id": "req1",
      "Content-ID": "<req1>"
    },
    "body": "{\n  \"my-key\": \"lorem\"\n}"
  },
  "req2": {
    "headers": {
      "x-frame-options": "deny",
      "…": "…",
      "x-subrequest-id": "req2",
      "Content-ID": "<req2>"
    },
    "body": "{\n  \"runs\": {\n  \"in\": \"parallel\"\n  }\n}"
  },
  "req1.1#uri{0}": {
    "headers": {
      "x-frame-options": "deny",
      "…": "…",
      "x-subrequest-id": "req1.1#uri{0}",
      "Content-ID": "<req1.1#uri{0}>"
    },
    "body": "{\n  \"akward\": [\"moar\", \"hip\", \"tests\"]\n}"
  },
  "req1.1.1#uri{0}": {
    "headers": {
      "connection": "close",
      "x-cache": "HIT",
      "source-age": "179",
      "…": "…",
      "x-subrequest-id": "req1.1.1#uri{0}",
      "Content-ID": "<req1.1.1#uri{0}>"
    },
    "body": "[\n  {\n  \"ha\": \"li\"\n  }\n]"
  },
  "req1.1.1#uri{1}": {
    "headers": {
      "content-type": "text/plain; charset=utf-8",
      "cache-control": "max-age=300",
      "…": "…",
      "x-subrequest-id": "req1.1.1#uri{1}",
      "Content-ID": "<req1.1.1#uri{1}>"
    },
    "body": "true"
  },
  "req1.1.1#uri{2}": {
    "headers": {
      "content-security-policy": "default-src 'none'; style-src 'unsafe-inline'",
      "…": "…",
      "x-subrequest-id": "req1.1.1#uri{2}",
      "Content-ID": "<req1.1.1#uri{2}>"
    },
    "body": "{\n  \"we need\": \"nonsensical strings\"\n}"
  }
}
1.13.0

6 years ago

1.12.0

6 years ago

1.11.1

6 years ago

1.11.0

6 years ago

1.10.0

6 years ago

1.9.0

6 years ago

1.8.0

6 years ago

1.7.0

7 years ago

1.6.0

7 years ago

1.5.0

7 years ago

1.4.0

7 years ago

1.3.0

7 years ago

1.2.0

7 years ago

1.1.0

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago