Batch Request Patch
Introduction
Batch Request is lightweight connect/express middleware for Node.js which allows clients to send multiple requests to a server running Node.js in batch. This library is derived from batch request. Due to project needs, I need to further process data after batch response. Therefore I patched it to fulfill following needs:
- I need it to have a typescript interface for typescript support.
- I need to further process data such as sign it for security purpose, hash it to ensure data integrity as well as help for my own caching infrastructure layer.
Looking for the Koa version of this module?
Prerequisite
Before you use this library, please keep in mind that you have used body-parser as one of your middlewares (express.bodyParser() or express.json() is needed). The official batch request documentation is somehow did not document it. However, it is mentioned in its source code batch-request/lib/batch-request.js line 48.
If you desire to use Typescript, just type tsd link in your command.
What Now
You can do as followings:
var batch = // Javascript/Typescript way. Simple
Optionally included 'batch.validate' middleware to check the validity of your batch request, as well as further process return data as you need:
// Include the batch.validate middleware before batch middleware app.post; //Typescript way. Recommended to write in this way: batchRouter.post;