elysia-msgpack
TypeScript icon, indicating that this package has built-in type declarations

0.2.1 • Public • Published

elysia-msgpack

The library for elysia which allows you to work with MessagePack. To pack/unpack it, we use really fast msgpackr

Installation

bun install elysia-msgpack

Usage

import Elysia from "elysia"
import { msgpack } from "elysia-msgpack"

new Elysia()
    .use(msgpack())
    .post("/", ({ body }) => {
        // body is unpacked MessagePack if content-type header contains application/x-msgpack


        // if accept header contains application/x-msgpack
        // this response will become a MessagePack,
        // and if not, it will remain JSON
        return {
            some: "values",
            and: true,
            keys: 228,
        }
    })
    .listen(3000)

Options

All options of msgpackr constructor

and mimeType - it's value to detect msgpack content-type and responding with it if accept contains this mimeType. Default is application/x-msgpack.

new Elysia()
    .use(msgpack({
        mimeType: "application/some-another-msgpack-type",
        int64AsType: "string",
        // and other msgpackr constructor options
    }))

You can use Apidog to test the API with msgpack.

Apidog

Package Sidebar

Install

npm i elysia-msgpack

Weekly Downloads

8

Version

0.2.1

License

none

Unpacked Size

4.12 kB

Total Files

4

Last publish

Collaborators

  • skravets