You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Automatic Message Pack detection (from the HTTP headers) and encoding of all JSON messages to Message Pack.
Extension of the current ExpressJS API; Introducing the Response.msgPack(jsObject) method on the standard ExpressJS Response object.
Getting Started
With auto-detection and transformation enabled, the middleware detects automatically the HTTP header Accept: application/x-msgpack and piggybacks the Response.json() method of the ExpressJS API, to encode the JSON response as Message Pack. This method is useful when you have existing applications that need to use the middleware, without changing the codebase very much.
constmsgpackResponse=require('msgpack-response');app.use(msgpackResponse({auto_detect: true}));app.get('/test_json',(req,res)=>{res.status(200).json({'message': 'a true test'});})
Note: Remember to add the header Accept: application/x-msgpack in the request.
Also, it can have auto-detection and transformation disabled. The middleware extends the Response object of the ExpressJS framework, by adding the msgPack() method to it. Then to return an encoded response, you just use the Response.msgPack() method that accepts the Javascript object as a parameter. For example,
constmsgpackResponse=require('msgpack-response');app.use(msgpackResponse({auto_detect: false}));//orapp.use(msgpackResponse());app.get('/test_msgpack',(req,res)=>{res.status(200).msgPack({'message': 'a true test'});});
Note: Initialize the middleware before the actual routes in the middleware chain to properly extend the Response Object.