Show / Hide Table of Contents

Class ApiCall<TRequest, TResponse>

Bridge between an RPC method (with synchronous and asynchronous variants) and higher level abstractions, applying call settings as required.

Inheritance
System.Object
ApiCall<TRequest, TResponse>
Inherited Members
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: Google.Api.Gax.Grpc
Assembly: Google.Api.Gax.Grpc.dll
Syntax
public sealed class ApiCall<TRequest, TResponse>
    where TRequest : class, IMessage<TRequest> where TResponse : class, IMessage<TResponse>
Type Parameters
Name Description
TRequest

RPC request type

TResponse

RPC response type

Properties

BaseCallSettings

The base CallSettings for this API call; these can be further overridden by providing a CallSettings to Async(TRequest, CallSettings) or Sync(TRequest, CallSettings).

Declaration
public CallSettings BaseCallSettings { get; }
Property Value
Type Description
CallSettings

Methods

Async(TRequest, CallSettings)

Performs an RPC call asynchronously.

Declaration
public Task<TResponse> Async(TRequest request, CallSettings perCallCallSettings)
Parameters
Type Name Description
TRequest request

The RPC request.

CallSettings perCallCallSettings

The call settings to apply to this specific call, overriding defaults where necessary.

Returns
Type Description
System.Threading.Tasks.Task<TResponse>

A task representing the asynchronous operation. The result of the completed task will be the RPC response.

Sync(TRequest, CallSettings)

Performs an RPC call synchronously.

Declaration
public TResponse Sync(TRequest request, CallSettings perCallCallSettings)
Parameters
Type Name Description
TRequest request

The RPC request.

CallSettings perCallCallSettings

The call settings to apply to this specific call, overriding defaults where necessary.

Returns
Type Description
TResponse

The RPC response.

WithCallSettingsOverlay(Func<TRequest, CallSettings>)

Constructs a new ApiCall<TRequest, TResponse> that applies an overlay to the underlying CallSettings. If a value exists in both the original and the overlay, the overlay takes priority.

Declaration
public ApiCall<TRequest, TResponse> WithCallSettingsOverlay(Func<TRequest, CallSettings> callSettingsOverlayFn)
Parameters
Type Name Description
System.Func<TRequest, CallSettings> callSettingsOverlayFn

Function that builds the overlay CallSettings.

Returns
Type Description
ApiCall<TRequest, TResponse>

A new ApiCall<TRequest, TResponse> with the overlay applied.

WithExceptionCustomizer(Func<RpcException, RpcException>)

Constructs a new ApiCall<TRequest, TResponse> that applies an exception customizer to both the synchronous and asynchronous calls.

Declaration
public ApiCall<TRequest, TResponse> WithExceptionCustomizer(Func<RpcException, RpcException> customizer)
Parameters
Type Name Description
System.Func<RpcException, RpcException> customizer

The exception customizer to apply. Must not be null.

Returns
Type Description
ApiCall<TRequest, TResponse>

A new ApiCall<TRequest, TResponse> with the exception customizer applied.

Remarks

customizer will be passed any exception that is thrown by the underlying API call. If it returns null, the original exception is retained and passed on. Otherwise, the returned exception is thrown in place of the original one.

WithGoogleRequestParam(String, Func<TRequest, String>)

Constructs a new ApiCall<TRequest, TResponse> that applies an x-goog-request-params header to each request, using the specified parameter name and a value derived from the request.

Declaration
public ApiCall<TRequest, TResponse> WithGoogleRequestParam(string parameterName, Func<TRequest, string> valueSelector)
Parameters
Type Name Description
System.String parameterName

The parameter name in the header. Must not be null.

System.Func<TRequest, System.String> valueSelector

A function to call on each request, to determine the value to specify in the header. The parameter must not be null, but may return null.

Returns
Type Description
ApiCall<TRequest, TResponse>

A new ApiCall<TRequest, TResponse> which applies the header on each request.

Remarks

Values produced by the function are URL-encoded; it is expected that parameterName is already URL-encoded.

Back to top