New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

elysia-msgpack

Package Overview
Dependencies
Maintainers
0
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

elysia-msgpack

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

  • 1.0.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-66.67%
Maintainers
0
Weekly downloads
 
Created
Source

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

// @filename: server.ts
import Elysia from "elysia"
import { msgpack } from "elysia-msgpack"

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


        //  also you can work with Packr instance via msgpack decorator

        // 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);

    export AppType = typeof app;

It works fine with End-to-End Type Safety too!

// @filename: client.ts
import { treaty } from "@elysiajs/eden";
import { pack, unpack } from "msgpackr";
import type { AppType } from "./server";

const app = treaty<AppType>("localhost:4888", {
    onRequest: (path, { body }) => {
        return {
            headers: {
                "content-type": "application/x-msgpack",
                accept: "application/x-msgpack",
            },
            body: pack(body),
        };
    },
    onResponse: async (response) => {
        if (
            response.headers
                .get("Content-Type")
                ?.startsWith("application/x-msgpack")
        )
            return unpack(Buffer.from(await response.arrayBuffer()));
    },
});

const { data, error } = await app.index.post({
    some: 228,
});

console.log(data);

Options

All options of msgpackr constructor (but we set useRecords to false by default)

KeyTypeDefaultDescription
contentTypes?string[]["application/x-msgpack"]An array of content-types that need to be serialized/deserialized
force?booleanfalseDon't look at the accept header to serialize?
as?LifeCycleType"scoped"Option to specify type of hooks
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

Keywords

FAQs

Package last updated on 24 Jun 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc