In order to be able to initialise a connection to a Volt, you will need to obtain a client configuration.
How your application obtains or stores the client configuration is not discussed here, needless to say you need to be careful not to expose keys or other sensitive data. For the purposes of this document, we assume the configuration is stored in a local file.
Create a client
Begin by creating a tdx Volt client instance:
Once initialised successfully, you can issue any API call.
Refer to the API documentation for details of the method names and corresponding request and response messages. Each API method expects a JSON object representing the request as input, and returns a JSON object as indicated by the response message type. The JSON representation of the protobuf message format is intuitive.
Unary calls
All unary calls will either resolve with a JSON response object matching that defined by the API protobuf, or reject if there is a problem with the websocket transport or an error status on the response object.
An example of issuing a unary call is shown below:
Streaming calls
The promise/future model does not fit well with streaming calls since they are long-lived.
For this reason, all streaming calls (client streaming, server streaming, and bi-directional streaming) return a call object that is used to manage the call.
The call object emits events as interactions with the underlying websocket occur, and there are 3 events of interest:
“error” emitted when an error occurs on the call
“data” emitted when a response is received from the Volt
“end” emitted when the call ends
An example of a streaming call is shown below:
Connection
The library supports creating a bi-directional Connect call to the Volt. This can be used to register to receive events from the Volt and to implement services that the Volt or other clients can call.
An example of creating a connection is shown below: