{"id":20727265,"url":"https://github.com/john-doherty/express-batch-requests","last_synced_at":"2025-04-23T18:51:18.436Z","repository":{"id":59363862,"uuid":"158077346","full_name":"john-doherty/express-batch-requests","owner":"john-doherty","description":"Express middleware to process batch HTTP requests","archived":false,"fork":false,"pushed_at":"2018-12-17T15:14:44.000Z","size":36,"stargazers_count":6,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-07T03:48:13.413Z","etag":null,"topics":["express","http","javascript","middleware","node","rest-api"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/john-doherty.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-11-18T11:37:25.000Z","updated_at":"2022-12-06T16:52:01.000Z","dependencies_parsed_at":"2022-09-15T21:13:25.152Z","dependency_job_id":null,"html_url":"https://github.com/john-doherty/express-batch-requests","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/john-doherty%2Fexpress-batch-requests","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/john-doherty%2Fexpress-batch-requests/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/john-doherty%2Fexpress-batch-requests/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/john-doherty%2Fexpress-batch-requests/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/john-doherty","download_url":"https://codeload.github.com/john-doherty/express-batch-requests/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224999518,"owners_count":17405053,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["express","http","javascript","middleware","node","rest-api"],"created_at":"2024-11-17T04:29:48.270Z","updated_at":"2024-11-17T04:29:48.892Z","avatar_url":"https://github.com/john-doherty.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# express-batch-requests\n\n[![Shippable branch](https://img.shields.io/shippable/5bf18eee3038210700d633d7/master.svg)](https://app.shippable.com/projects/5bf18eee3038210700d633d7)\n[![Linked In](https://img.shields.io/badge/Linked-In-blue.svg)](https://www.linkedin.com/in/john-i-doherty) [![Twitter Follow](https://img.shields.io/twitter/follow/mrJohnDoherty.svg?style=social\u0026label=Twitter\u0026style=plastic)](https://twitter.com/mrJohnDoherty)\n\nA simple way to add HTTP batch request support to your node API using express middleware.\n\nBatching HTTP requests allows client applications to issue multiple HTTP requests to your API using just one HTTP request - reducing network chatter, latency etc. This middleware extracts and executes each request individually, either in parallel or in series, and returns the result of each request as an array item.\n\n## Installation\n\n```bash\nnpm install --save express-batch-requests\n```\n\n## Usage\n\n```js\nvar express = require('express');\nvar server = express();\nvar expressBatchRequests = require('express-batch-requests');\n\n// mount the batch handler middleware\nserver.post('/batch', expressBatchRequests);\n\n// typical API route 1\nserver.get('/route1', function (req, res) {\n    res.send(\"Hello World\");\n});\n\n// typical API route 2\nserver.post('/route2', function (req, res) {\n    res.json({\n        fullName: req.body.firstName + ' ' + req.body.lastName\n    });\n});\n\n// start the server\nserver.listen(8080, function () {\n    console.log('Web server listening on port 8080');\n});\n```\n\n## Request\n\nRequests are executed in parallel by default, to execute them in series add `executeInSeries: true`. Likewise, to include the original request object with each result add `includeRequestsInResponse: true` to the request.\n\nTo copy HTTP headers from the batch request onto each of the batch request such as **authorization**, add `mergeHeaders` with a string containing a comma separated list of header names _(in lower case)_.\n\n```json\n{\n    \"executeInSeries\": true,\n    \"includeRequestsInResponse\": true,\n    \"mergeHeaders\": \"authorization, x-requested-by\",\n    \"batch\": [\n        {\n            \"url\": \"/route1\",\n            \"method\": \"GET\"\n        },\n        {\n            \"url\": \"/route2\",\n            \"method\": \"POST\",\n            \"headers\": {\n                \"User-Agent\": \"space-command\"\n            },\n            \"body\": {\n                \"firstName\": \"Buzz\",\n                \"lastName\": \"Lightyear\"\n            }\n        }\n    ]\n}\n```\n\n## Response\n\n```json\n[\n    {\n        \"request\": {\n            \"url\": \"/route1\",\n            \"method\": \"GET\"\n        },\n        \"response\": {\n            \"code\": 200,\n            \"headers\": {\n                \"content-type\": \"text/plain\"\n            },\n            \"body\": \"Hello World\"\n        }\n    },\n    {\n        \"request\": {\n            \"url\": \"/route2\",\n            \"method\": \"POST\",\n            \"headers\": {\n                \"User-Agent\": \"space-command\"\n            },\n            \"body\": {\n                \"firstName\": \"Buzz\",\n                \"lastName\": \"Lightyear\"\n            }\n        },\n        \"response\": {\n            \"code\": 200,\n            \"headers\": {\n                \"content-type\": \"application/json\"\n            },\n            \"body\": {\n                \"fullName\": \"Buzz Lightyear\"\n            }\n        }\n    }\n]\n```\n\n## Star the repo\n\nIf you find this useful star the repo as it helps me prioritize which bugs to tackle first.\n\n## History\n\nFor change-log, check [releases](https://github.com/john-doherty/express-batch-requests/releases).\n\n## License\n\nLicensed under [MIT License](LICENSE) \u0026copy; [John Doherty](http://www.johndoherty.info)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohn-doherty%2Fexpress-batch-requests","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjohn-doherty%2Fexpress-batch-requests","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohn-doherty%2Fexpress-batch-requests/lists"}