new Client(address, credentials, options)
A generic gRPC client. Primarily useful as a base class for generated clients
Parameters:
Name | Type | Description | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
address |
string | Server address to connect to |
||||||||||||||||||||||||
credentials |
grpc.credentials~ChannelCredentials | Credentials to use to connect to the server |
||||||||||||||||||||||||
options |
Object | Options to apply to channel creation. Any of the channel arguments can be used here in addition to specific client options. Properties
|
Methods
-
close()
-
Close this client.
-
getChannel()
-
Return the underlying channel object for the specified client
Returns:
The channel
- Type
- Channel
-
makeBidiStreamRequest(path, serialize, deserialize [, metadata] [, options])
-
Make a bidirectional stream request with this method on the given channel.
Parameters:
Name Type Argument Description path
string The path of the method to request
serialize
grpc~serialize The serialization function for inputs
deserialize
grpc~deserialize The deserialization function for outputs
metadata
grpc.Metadata <optional>
Array of metadata key/value pairs to add to the call
options
grpc.Client~CallOptions <optional>
Options map
Returns:
An event emitter for stream related events
-
makeClientStreamRequest(path, serialize, deserialize [, metadata] [, options], callback)
-
Make a client stream request to the given method, using the given serialize and deserialize functions, with the given argument.
Parameters:
Name Type Argument Description path
string The path of the method to request
serialize
grpc~serialize The serialization function for inputs
deserialize
grpc~deserialize The deserialization function for outputs
metadata
grpc.Metadata <optional>
Array of metadata key/value pairs to add to the call
options
grpc.Client~CallOptions <optional>
Options map
callback
grpc.Client~requestCallback The callback for when the response is received
Returns:
An event emitter for stream related events
-
makeServerStreamRequest(path, serialize, deserialize, argument [, metadata] [, options])
-
Make a server stream request to the given method, with the given serialize and deserialize function, using the given argument
Parameters:
Name Type Argument Description path
string The path of the method to request
serialize
grpc~serialize The serialization function for inputs
deserialize
grpc~deserialize The deserialization function for outputs
argument
* The argument to the call. Should be serializable with serialize
metadata
grpc.Metadata <optional>
Array of metadata key/value pairs to add to the call
options
grpc.Client~CallOptions <optional>
Options map
Returns:
An event emitter for stream related events
-
makeUnaryRequest(path, serialize, deserialize, argument [, metadata] [, options], callback)
-
Make a unary request to the given method, using the given serialize and deserialize functions, with the given argument.
Parameters:
Name Type Argument Description path
string The path of the method to request
serialize
grpc~serialize The serialization function for inputs
deserialize
grpc~deserialize The deserialization function for outputs
argument
* The argument to the call. Should be serializable with serialize
metadata
grpc.Metadata <optional>
Metadata to add to the call
options
grpc.Client~CallOptions <optional>
Options map
callback
grpc.Client~requestCallback The callback for when the response is received
Returns:
An event emitter for stream related events
- Type
- grpc~ClientUnaryCall
-
waitForReady(deadline, callback)
-
Wait for the client to be ready. The callback will be called when the client has successfully connected to the server, and it will be called with an error if the attempt to connect to the server has unrecoverablly failed or if the deadline expires. This function will make the channel start connecting if it has not already done so.
Parameters:
Name Type Description deadline
grpc~Deadline When to stop waiting for a connection.
callback
function The callback to call when done attempting to connect.
-
<inner> callInvocationTransformer(callProperties)
-
Call invocation transformer. Has access to the full call properties before a call is processed and can modify most of those properties. Some modifications will have no effect or may cause problems.
Parameters:
Name Type Description callProperties
grpc.Client~CallProperties The original call properties
Returns:
The modified call properties.
-
<inner> channelFactory(target, credentials, options)
-
A function that functionally replaces the Channel constructor.
Parameters:
Name Type Description target
string The address of the server to connect to
credentials
grpc.ChannelCredentials Channel credentials to use when connecting
options
grpc~ChannelOptions A map of channel options that will be passed to the core. The available options are listed in this document.
Returns:
This can either be an actual channel object, or an object with the same API.
- Type
- grpc.Channel
Type Definitions
-
Call
-
Any client call type
Type:
- grpc~ClientUnaryCall | grpc~ClientReadableStream | grpc~ClientWritableStream | grpc~ClientDuplexStream
-
CallOptions
-
Options that can be set on a call.
Type:
- Object
Properties:
Name Type Description deadline
grpc~Deadline The deadline for the entire call to complete.
host
string Server hostname to set on the call. Only meaningful if different from the server address used to construct the client.
parent
grpc.Client~Call Parent call. Used in servers when making a call as part of the process of handling a call. Used to propagate some information automatically, as specified by propagate_flags.
propagate_flags
number Indicates which properties of a parent call should propagate to this call. Bitwise combination of flags in grpc.propagate.
credentials
grpc.credentials~CallCredentials The credentials that should be used to make this particular call.
-
CallProperties
-
Properties of a call, for use with a grpc.Client~callInvocationTransformer.
Type:
- Object
Properties:
Name Type Description argument
* The call argument. Only preset if the method is unary or server streaming.
metadata
grpc.Metadata The request metadata
call
grpc~Call The call object that will be returned by the client method
channel
grpc.Channel The channel that will be used to make a request
methodDefinition
grpc~MethodDefinition The MethodDefinition object that describes this method
options
grpc.Client~CallOptions The call options passed when making this request
callback
grpc.Client~requestCallback The callback that will handle the response. Only present if this method is unary or client streaming.
-
requestCallback(error, value)
-
Parameters:
Name Type Argument Description error
grpc~ServiceError <nullable>
The error, if the call failed
value
* The response value, if the call succeeded