diff --git a/clients/algoliasearch-client-csharp/algoliasearch/Transport/HttpTransport.cs b/clients/algoliasearch-client-csharp/algoliasearch/Transport/HttpTransport.cs index d0f0fa42d5..60ef846c14 100644 --- a/clients/algoliasearch-client-csharp/algoliasearch/Transport/HttpTransport.cs +++ b/clients/algoliasearch-client-csharp/algoliasearch/Transport/HttpTransport.cs @@ -24,6 +24,10 @@ internal class HttpTransport private readonly AlgoliaConfig _algoliaConfig; private string _errorMessage; + private class VoidResult + { + } + /// /// Instantiate the transport class with the given configuration and requester /// @@ -52,6 +56,19 @@ public async Task ExecuteRequestAsync(HttpMethod method, strin await ExecuteRequestAsync(method, uri, requestOptions, ct) .ConfigureAwait(false); + /// + /// Execute the request, without response + /// + /// The HttpMethod + /// The endpoint URI + /// Add extra http header or query parameters to Algolia + /// Optional cancellation token + public async Task ExecuteRequestAsync(HttpMethod method, string uri, + InternalRequestOptions requestOptions = null, + CancellationToken ct = default) => + await ExecuteRequestAsync(method, uri, requestOptions, ct) + .ConfigureAwait(false); + /// /// Call api with retry strategy /// @@ -93,7 +110,8 @@ private async Task ExecuteRequestAsync(HttpMethod metho foreach (var host in _retryStrategy.GetTryableHost(callType)) { request.Body = CreateRequestContent(requestOptions?.Data, request.CanCompress); - request.Uri = BuildUri(host.Url, uri, requestOptions?.CustomPathParameters, requestOptions?.PathParameters, requestOptions?.QueryParameters); + request.Uri = BuildUri(host.Url, uri, requestOptions?.CustomPathParameters, requestOptions?.PathParameters, + requestOptions?.QueryParameters); var requestTimeout = TimeSpan.FromTicks((requestOptions?.Timeout ?? GetTimeOut(callType)).Ticks * (host.RetryCount + 1)); @@ -111,6 +129,11 @@ private async Task ExecuteRequestAsync(HttpMethod metho switch (_retryStrategy.Decide(host, response)) { case RetryOutcomeType.Success: + if (typeof(TResult) == typeof(VoidResult)) + { + return new VoidResult() as TResult; + } + return await _serializer.Deserialize(response.Body); case RetryOutcomeType.Retry: continue; @@ -158,7 +181,8 @@ private IDictionary GenerateHeaders(IDictionary /// /// /// - private Uri BuildUri(string url, string baseUri, IDictionary customPathParameters = null, IDictionary pathParameters = null, + private Uri BuildUri(string url, string baseUri, IDictionary customPathParameters = null, + IDictionary pathParameters = null, IDictionary optionalQueryParameters = null) { var path = $"{baseUri}"; diff --git a/templates/csharp/libraries/httpclient/api.mustache b/templates/csharp/libraries/httpclient/api.mustache index dc03960a33..8457d2ab99 100644 --- a/templates/csharp/libraries/httpclient/api.mustache +++ b/templates/csharp/libraries/httpclient/api.mustache @@ -38,7 +38,7 @@ namespace Algolia.Search.Clients {{#isDeprecated}} [Obsolete] {{/isDeprecated}} - Task<{{> return_type}}> {{operationId}}Async{{#returnType}}{{#vendorExtensions.x-is-generic}}{{/vendorExtensions.x-is-generic}}{{/returnType}}({{#allParams}}{{{dataType}}}{{#isEnumRef}}{{^required}}?{{/required}}{{/isEnumRef}} {{paramName}}{{^required}}{{#optionalMethodArgument}} = default{{/optionalMethodArgument}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}{{#allParams.0}}, {{/allParams.0}}RequestOptions options = null, CancellationToken cancellationToken = default); + Task{{#returnType}}<{{> return_type}}>{{/returnType}} {{operationId}}Async{{#returnType}}{{#vendorExtensions.x-is-generic}}{{/vendorExtensions.x-is-generic}}{{/returnType}}({{#allParams}}{{{dataType}}}{{#isEnumRef}}{{^required}}?{{/required}}{{/isEnumRef}} {{paramName}}{{^required}}{{#optionalMethodArgument}} = default{{/optionalMethodArgument}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}{{#allParams.0}}, {{/allParams.0}}RequestOptions options = null, CancellationToken cancellationToken = default); {{/operation}} } {{/supportsAsync}} @@ -114,7 +114,7 @@ namespace Algolia.Search.Clients {{#isDeprecated}} [Obsolete] {{/isDeprecated}} - public async Task<{{> return_type}}> {{operationId}}Async{{#returnType}}{{#vendorExtensions.x-is-generic}}{{/vendorExtensions.x-is-generic}}{{/returnType}}({{#allParams}}{{{dataType}}}{{#isEnumRef}}{{^required}}?{{/required}}{{/isEnumRef}} {{paramName}}{{^required}}{{#optionalMethodArgument}} = default{{/optionalMethodArgument}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}{{#allParams.0}}, {{/allParams.0}}RequestOptions options = null, CancellationToken cancellationToken = default) + public async Task{{#returnType}}<{{> return_type}}>{{/returnType}} {{operationId}}Async{{#returnType}}{{#vendorExtensions.x-is-generic}}{{/vendorExtensions.x-is-generic}}{{/returnType}}({{#allParams}}{{{dataType}}}{{#isEnumRef}}{{^required}}?{{/required}}{{/isEnumRef}} {{paramName}}{{^required}}{{#optionalMethodArgument}} = default{{/optionalMethodArgument}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}{{#allParams.0}}, {{/allParams.0}}RequestOptions options = null, CancellationToken cancellationToken = default) { {{#allParams}} {{#required}} @@ -184,7 +184,7 @@ namespace Algolia.Search.Clients requestOptions.UseReadTransporter = true; {{/x-use-read-transporter}} {{/vendorExtensions}} - return await _transport.ExecuteRequestAsync<{{> return_type}}>(new HttpMethod("{{httpMethod}}"),"{{{path}}}", requestOptions, cancellationToken).ConfigureAwait(false); + {{#returnType}}return {{/returnType}}await _transport.ExecuteRequestAsync{{#returnType}}<{{> return_type}}>{{/returnType}}(new HttpMethod("{{httpMethod}}"),"{{{path}}}", requestOptions, cancellationToken).ConfigureAwait(false); } {{/supportsAsync}} {{/operation}}