RClient is a simplified way to use RSocket in the browser. It is setup to support routing, bearer authentication and json serialization out of the box. It utilises rxjs library to provide a convenient way to deal with streams.
npm:
npm install rclient
yarn:
yarn add rclient
import { connect } from "rclient";
const client = await connect("ws://localhost:8888/rsocket");
Sends the data to the server and doesn't wait for the response
Signature:
fireAndForget(path: string, token: string, data: string): Observable<void>
path: message/x.rsocket.routing.v0 route
token: bearer token sent to the server
data: java object
Usage:
this.client.fireAndForget("messages", "", { text: "Hello World" }).subscribe()
Sends the data to the server and returns a single response
Signature:
requestResponse(path: string, token: string, data: string): Observable<any>
path: message/x.rsocket.routing.v0 route
token: bearer token sent to the server
data: java object
Usage:
this.client.requestResponse("messages", "", { text: "Hello World" })
.subscribe(response => console.log(response))
Sends the data to the server and returns a stream of responses
Signature:
requestStream(path: string, token: string, data: string): Observable<any>
path: message/x.rsocket.routing.v0 route
token: bearer token sent to the server
data: java object
Usage:
this.client.requestStream("messages", "", { text: "Hello World" })
.subscribe(response => console.log(response))
- NOT IMPLEMENTED