Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/svi3c/node-beamed

A blazing fast, slim communication protocol for IPC.
https://github.com/svi3c/node-beamed

Last synced: 12 days ago
JSON representation

A blazing fast, slim communication protocol for IPC.

Awesome Lists containing this project

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 |