Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kenriortega/fastify-msgpack
Fastify and MessagePack, together at last. Uses @msgpack/msgpack by default.
https://github.com/kenriortega/fastify-msgpack
fastify msgpack
Last synced: 2 months ago
JSON representation
Fastify and MessagePack, together at last. Uses @msgpack/msgpack by default.
- Host: GitHub
- URL: https://github.com/kenriortega/fastify-msgpack
- Owner: kenriortega
- License: mit
- Created: 2021-05-17T01:11:06.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-05-18T22:53:16.000Z (over 3 years ago)
- Last Synced: 2024-10-14T02:31:00.882Z (2 months ago)
- Topics: fastify, msgpack
- Language: JavaScript
- Homepage:
- Size: 333 KB
- Stars: 10
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- cuban-opensource - fastify-msgpack
README
# Fastify-msgpack
Fastify and MessagePack, together at last. Uses @msgpack/msgpack by default.
## Functionality
Provides transparent middleware that can be used to support clients requesting Accept: application/msgpack from endpoints using res.json or sending Content-Type: application/msgpack to any endpoint. You can continue to use req.body and res.json and fastifyMsgpack will handle the conversion in the background using @msgpack/msgpack.
Installation
------------```bash
$ npm install --save fastify-msgpack
// or
$ yarn add fastify-msgpack
```
Test
----
```bash
$ npm test```
Usage
-----```javascript
const fastifyMsgpack = require("fastify-msgpack");// ...
// custom plugin
fastify.register(fastifyMsgpack)
```Usage in a simple app
---------------------```javascript
'use strict'const fastify = require('fastify')({
logger: true
})// custom plugin
fastify.register(require('fastify-msgpack'))fastify.post('/decode', (req, reply) => {
// http POST http://localhost:5000/decode Accept:application/msgpack Content-Type:application/msgpack @msgpack\package-msgpack.datconst body = req.body
return body
})
fastify.get('/encode', (req, reply) => {
// http http://localhost:5000/encode Accept:application/msgpackreply.send({ hello: 'fastify-plugin' })
})const start = async () => {
try {
await fastify.listen(5000)
} catch (err) {
fastify.log.error(err)
process.exit(1)
}
}start()
```