Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/svi3c/node-beamed
A blazing fast, slim communication protocol for IPC.
https://github.com/svi3c/node-beamed
Last synced: about 1 month ago
JSON representation
A blazing fast, slim communication protocol for IPC.
- Host: GitHub
- URL: https://github.com/svi3c/node-beamed
- Owner: svi3c
- License: mit
- Created: 2020-06-23T05:02:37.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-01-06T09:38:49.000Z (almost 2 years ago)
- Last Synced: 2024-04-23T17:53:37.262Z (8 months ago)
- Language: TypeScript
- Size: 935 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-blazingly-fast - node-beamed - A blazing fast, slim communication protocol for IPC. (TypeScript)
README
# beamed
[![Build Status](https://travis-ci.com/svi3c/node-beamed.svg?branch=master)](https://travis-ci.com/github/svi3c/node-beamed)
> A blazing fast, slim communication protocol for NodeJS IPC.
[![NPM](https://nodei.co/npm/beamed.png)](https://www.npmjs.com/package/beamed)
## Features
- A lightweight protocol minimizes network traffic and provides high processing performance
- The TypeScript API enables you to specify strictly typed endpoints and reuse the same type definitions on client and server side
- Support for Unix, Windows, TCP and TLS sockets
- Requesting, messaging and publish / subscribe
- Send any payload (objects, buffers and strings)
- No third party dependencies## Example
`shared.ts`
```ts
enum AuthTopics {
login, // can be strings or numbers
}
interface AuthApi {
[AuthTopics.login]: {
req: Credentials;
res: User;
};
}
````server.ts`
```ts
import { createServer } from "beamed";
import { AuthApi, AuthTopics } from "./shared";const bs = createServer()
.onRequest(AuthTopics.login, authenticate)
.listen("/tmp/auth-test");
````client.ts`
```ts
import { connect } from "beamed";
import { AuthApi, AuthTopics } from "./shared";const bc = connect("/tmp/auth-test");
bc.request(AuthTopics.login, new Credentials("user", "p4ssw0rd")).then((user) =>
console.log(user)
);
```## Protocol
Message types (Not completely implementing yet).
| Type | Message-Pattern | Examples |
| -------------- | ---------------------------------------- | -------------------------------------- |
| Request | `?\|[\|payload]` | `19?1\|8\|J{"foo":"bar"}`
`5?2\|45` |
| Response | `.[\|payload]` | `17.8\|J{"foo":"bar"}`
`3.45` |
| Error-Response | `X\|[\|message]` | `17.8\|J{"foo":"bar"}`
`6X45\|42` |
| Subscribe | `+` | `2+1` |
| Unsubscribe | `-` | `2-1` |
| Message / Push | `![\|payload]` | `17!1\|J{"foo":"bar"}`
`2!2` |Where the tokens have the following format
| Token | Format | Note |
| ---------- | ------------------- | ------------------------------------------------------------------------------------------------------------------ |
| length | numeric | The byte length of the message content without this length (auto-generated) |
| topic | utf-8 (except `\|`) | You can use TS Enums |
| id | numeric | The request id (auto-generated) |
| error-code | utf-8 (except `\|`) | You can use TS Enums |
| message | utf-8 | Custom Error decription |
| payload | utf-8 or Buffer | Prefixed by a character that determines the content type:
`J` for Json,
`B` for binary data,
`T` for text |