@zwoo/api-zrp
v1.0.0
Published
A ZRP implementation in TypeScript.
Downloads
55
Readme
@zwoo/api-zrp
A ZRP implementation in TypeScript.
Quickstart
Install the package via npm/yarn/pnpm:
npm i @zwoo/api-zrp
yarn add @zwoo/api-zrp
pnpm add @zwoo/api-zrp
Usage
There a few main parts to use:
ZRPCoder
: The coder is used to encode and decode messages.ZRPMessageBuilder
: The message builder is used to build messages.
All payload types are strongly typed using typescript based on the ZRPCode. These utility types are also exported:
ZRPMessage<ZRPCode>
: a typed message with the correct payload type for the codeZRPMessage<T>
: a typed message with a custom payload typeZRPPayload
: a utility to get the payload type for a zrp code
Example
import { ZRPCoder, ZRPMessageBuilder } from '@zwoo/api-zrp';
const { code, payload } = ZRPCoder.decode('...raw zrp message...');
const message = ZRPMessageBuilder.build(ZRPCode, { ... })
const rawMessage = ZRPCoder.encode(message);