elysia-msgpack
Advanced tools
Comparing version 0.0.1 to 0.0.2
{ | ||
"name": "elysia-msgpack", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"module": "src/index.js", | ||
"type": "module", | ||
"scripts": { | ||
"prepublishOnly": "tsc", | ||
"dev": "bun run --watch src/index.ts", | ||
@@ -15,3 +16,3 @@ "lint": "eslint \"src/**/*.{ts,tsx,js,mjs,cjs}\"", | ||
"peerDependencies": { | ||
"elysia": "^0.7.29" | ||
"elysia": "^0.7.0" | ||
}, | ||
@@ -18,0 +19,0 @@ "devDependencies": { |
# elysia-msgpack | ||
A library for [elysia](elysia) that allows you to work with [MessagePack](https://msgpack.org/) | ||
A library for [elysia](elysia) that allows you to work with [MessagePack](https://msgpack.org/). To pack/unpack it we use really fast [msgpackr](https://github.com/kriszyp/msgpackr) | ||
@@ -15,13 +15,37 @@ ## Example | ||
.post("/", ({ body }) => { | ||
//body is unpacked MessagePack if content-type header contains application/x-msgpack | ||
// 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, | ||
} | ||
}) | ||
// 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](https://github.com/kriszyp/msgpackr?tab=readme-ov-file#options) | ||
and `mimeType` - it's value to detect msgpack content-type and responding with it if accept contains this `mimeType`. Default is `application/x-msgpack`. | ||
<!-- prettier-ignore --> | ||
```ts | ||
new Elysia() | ||
.use(msgpack({ | ||
mimeType: "application/some-another-msgpack-type", | ||
int64AsType: "string", | ||
// and other msgpackr constructor options | ||
})) | ||
``` | ||
You can use [Apidog](https://apidog.com/) to test the API with msgpack. | ||
<div align='center'> | ||
<img src="https://github.com/kravetsone/elysia-msgpack/assets/57632712/25a3761e-4121-4849-9d77-a73b96227685" alt="Apidog" /> | ||
</div> |
3304
51