Package Exports
- @jsonjoy.com/rpc-messages
- @jsonjoy.com/rpc-messages/lib/index.js
- @jsonjoy.com/rpc-messages/lib/validation
- @jsonjoy.com/rpc-messages/lib/validation.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@jsonjoy.com/rpc-messages) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@jsonjoy.com/rpc-messages
Message types for the JSON Reactive RPC protocol. JSON Rx is a lightweight bi-directional RPC protocol with reactive (Observable) request and response payloads. It supports notifications, request/response, and full bidirectional streaming over any message-passing transport (WebSocket, HTTP, IPC, etc.).
Usage
import {
NotificationMessage,
RequestDataMessage,
RequestCompleteMessage,
RequestErrorMessage,
RequestUnsubscribeMessage,
ResponseDataMessage,
ResponseCompleteMessage,
ResponseErrorMessage,
ResponseUnsubscribeMessage,
} from '@jsonjoy.com/rpc-messages';Messages
JSON Rx defines nine message types split between client-sent and server-sent messages.
Client to Server
| Class | Description |
|---|---|
NotificationMessage |
Fire-and-forget notification; no response expected. |
RequestDataMessage |
Initiates a subscription or emits a value into an existing one. |
RequestCompleteMessage |
Starts and immediately completes a subscription (unary request). |
RequestErrorMessage |
Starts and immediately completes a subscription with an error. |
ResponseUnsubscribeMessage |
Client cancels an active response subscription. |
Server to Client
| Class | Description |
|---|---|
NotificationMessage |
Fire-and-forget notification from server. |
ResponseDataMessage |
Emits a value in a response subscription. |
ResponseCompleteMessage |
Completes a response subscription (with an optional final value). |
ResponseErrorMessage |
Completes a response subscription with an error. |
RequestUnsubscribeMessage |
Server asks client to stop a request subscription. |
Communication patterns
- Notification — client sends one
NotificationMessage; server sends nothing back. - Request/response — client sends
RequestCompleteMessage; server sendsResponseCompleteMessage. Both sides emit exactly one value. - Server-streaming — client sends
RequestCompleteMessage; server sends zero or moreResponseDataMessages followed byResponseCompleteMessage. - Client-streaming — client sends one or more
RequestDataMessages followed byRequestCompleteMessage; server sendsResponseCompleteMessage. - Bidirectional streaming — client streams
RequestDataMessages; server streamsResponseDataMessages.
Validation
Every message class exposes a validate() method that throws an
RpcError (BAD_REQUEST) if the message fields are invalid
(e.g. id out of range, method name contains illegal characters).