Skip to content

ExpressJS msgpack response middleware / msgpack.org[Node]

License

Notifications You must be signed in to change notification settings

sschizas/msgpack-response

Repository files navigation

msgpack-response

Node.js CI Dependency Status Contributor Covenant License: MIT

An implementation of Message Pack middleware for ExpressJS.

Features

  • 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.

const msgpackResponse = 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,

const msgpackResponse = require('msgpack-response');

app.use(msgpackResponse({auto_detect: false}));
//or
app.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.

Requirements

Node.js >= 6.0

Installation

With npm do:

npm install msgpack-response -save

About

I ❤️ open source software!

Check out my other open source projects or say 👋 on twitter.

Contribute

Contributions are welcome 🤘. Please see the Contributing Guide and the Code of Conduct.

Authors

  • Stavros Schizas - Initial work & Maintainer
  • Vassilios Karakoidas - Initial work - Wizhut

See also the list of contributors who participated in this project.

License

msgpack-response is available under the MIT license. See the LICENSE file for more info.

About

ExpressJS msgpack response middleware / msgpack.org[Node]

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •