Add ReCClientOptions for configurable client behavior

Introduced a new `ReCClientOptions` property to `BaseCrudApi`
and its derived classes to enhance flexibility and control
over client behavior. Updated constructors to accept an
optional `ReCClientOptions` parameter, with default options
applied when omitted.

Modified `CreateAsync`, `UpdateAsync`, and other methods in
`BaseCrudApi` to utilize the `Options.LogSuccessfulRequests`
property for more granular logging control. Updated derived
API classes (`CommonApi`, `EndpointAuthApi`, `EndpointParamsApi`,
`EndpointsApi`, `ProfileApi`, `RecActionApi`, and `ResultApi`)
to pass the `options` parameter to the base constructor.

Ensured compatibility with both `NETFRAMEWORK` and other
frameworks by using nullable annotations where applicable.
These changes improve the extensibility and maintainability
of the API client.
This commit is contained in:
2026-05-19 19:20:54 +02:00
parent 01ac7ece1e
commit 6d8e51ad70
8 changed files with 34 additions and 20 deletions

View File

@@ -30,21 +30,28 @@ namespace ReC.Client.Api
protected readonly ILogger? Logger;
#endif
/// <summary>
/// The options controlling client behavior. Never <see langword="null"/>.
/// </summary>
protected readonly ReCClientOptions Options;
/// <summary>
/// Initializes a new instance of the <see cref="BaseCrudApi"/> class.
/// </summary>
/// <param name="http">The HTTP client used for requests.</param>
/// <param name="resourcePath">The base resource path for the API endpoint.</param>
/// <param name="logger">An optional logger used to record API call outcomes.</param>
/// <param name="options">An optional set of client options. Defaults are used when omitted.</param>
#if NETFRAMEWORK
protected BaseCrudApi(HttpClient http, string resourcePath, ILogger logger = null)
protected BaseCrudApi(HttpClient http, string resourcePath, ILogger logger = null, ReCClientOptions options = null)
#else
protected BaseCrudApi(HttpClient http, string resourcePath, ILogger? logger = null)
protected BaseCrudApi(HttpClient http, string resourcePath, ILogger? logger = null, ReCClientOptions? options = null)
#endif
{
Http = http ?? throw new ArgumentNullException(nameof(http));
ResourcePath = resourcePath ?? throw new ArgumentNullException(nameof(resourcePath));
Logger = logger;
Options = options ?? new ReCClientOptions();
}
/// <summary>
@@ -59,7 +66,7 @@ namespace ReC.Client.Api
using (var content = ReCClientHelpers.ToJsonContent(payload))
using (var resp = await Http.PostAsync(ResourcePath, content, cancel))
{
await ReCClientHelpers.HandleResponseAsync(resp, Logger, cancel).ConfigureAwait(false);
await ReCClientHelpers.HandleResponseAsync(resp, Logger, Options.LogSuccessfulRequests, cancel).ConfigureAwait(false);
}
}
@@ -76,7 +83,7 @@ namespace ReC.Client.Api
using (var content = ReCClientHelpers.ToJsonContent(payload))
using (var resp = await Http.PutAsync($"{ResourcePath}/{id}", content, cancel))
{
await ReCClientHelpers.HandleResponseAsync(resp, Logger, cancel).ConfigureAwait(false);
await ReCClientHelpers.HandleResponseAsync(resp, Logger, Options.LogSuccessfulRequests, cancel).ConfigureAwait(false);
}
}
@@ -95,7 +102,7 @@ namespace ReC.Client.Api
})
using (var resp = await Http.SendAsync(request, cancel))
{
await ReCClientHelpers.HandleResponseAsync(resp, Logger, cancel).ConfigureAwait(false);
await ReCClientHelpers.HandleResponseAsync(resp, Logger, Options.LogSuccessfulRequests, cancel).ConfigureAwait(false);
}
}
}

View File

@@ -15,10 +15,11 @@ namespace ReC.Client.Api
/// </summary>
/// <param name="http">The HTTP client used for requests.</param>
/// <param name="logger">An optional logger used to record API call outcomes.</param>
/// <param name="options">An optional set of client options. Defaults are used when omitted.</param>
#if NETFRAMEWORK
public CommonApi(HttpClient http, ILogger logger = null) : base(http, "api/Common", logger)
public CommonApi(HttpClient http, ILogger logger = null, ReCClientOptions options = null) : base(http, "api/Common", logger, options)
#else
public CommonApi(HttpClient http, ILogger? logger = null) : base(http, "api/Common", logger)
public CommonApi(HttpClient http, ILogger? logger = null, ReCClientOptions? options = null) : base(http, "api/Common", logger, options)
#endif
{
}

View File

@@ -15,10 +15,11 @@ namespace ReC.Client.Api
/// </summary>
/// <param name="http">The HTTP client used for requests.</param>
/// <param name="logger">An optional logger used to record API call outcomes.</param>
/// <param name="options">An optional set of client options. Defaults are used when omitted.</param>
#if NETFRAMEWORK
public EndpointAuthApi(HttpClient http, ILogger logger = null) : base(http, "api/EndpointAuth", logger)
public EndpointAuthApi(HttpClient http, ILogger logger = null, ReCClientOptions options = null) : base(http, "api/EndpointAuth", logger, options)
#else
public EndpointAuthApi(HttpClient http, ILogger? logger = null) : base(http, "api/EndpointAuth", logger)
public EndpointAuthApi(HttpClient http, ILogger? logger = null, ReCClientOptions? options = null) : base(http, "api/EndpointAuth", logger, options)
#endif
{
}

View File

@@ -15,10 +15,11 @@ namespace ReC.Client.Api
/// </summary>
/// <param name="http">The HTTP client used for requests.</param>
/// <param name="logger">An optional logger used to record API call outcomes.</param>
/// <param name="options">An optional set of client options. Defaults are used when omitted.</param>
#if NETFRAMEWORK
public EndpointParamsApi(HttpClient http, ILogger logger = null) : base(http, "api/EndpointParams", logger)
public EndpointParamsApi(HttpClient http, ILogger logger = null, ReCClientOptions options = null) : base(http, "api/EndpointParams", logger, options)
#else
public EndpointParamsApi(HttpClient http, ILogger? logger = null) : base(http, "api/EndpointParams", logger)
public EndpointParamsApi(HttpClient http, ILogger? logger = null, ReCClientOptions? options = null) : base(http, "api/EndpointParams", logger, options)
#endif
{
}

View File

@@ -15,10 +15,11 @@ namespace ReC.Client.Api
/// </summary>
/// <param name="http">The HTTP client used for requests.</param>
/// <param name="logger">An optional logger used to record API call outcomes.</param>
/// <param name="options">An optional set of client options. Defaults are used when omitted.</param>
#if NETFRAMEWORK
public EndpointsApi(HttpClient http, ILogger logger = null) : base(http, "api/Endpoints", logger)
public EndpointsApi(HttpClient http, ILogger logger = null, ReCClientOptions options = null) : base(http, "api/Endpoints", logger, options)
#else
public EndpointsApi(HttpClient http, ILogger? logger = null) : base(http, "api/Endpoints", logger)
public EndpointsApi(HttpClient http, ILogger? logger = null, ReCClientOptions? options = null) : base(http, "api/Endpoints", logger, options)
#endif
{
}

View File

@@ -15,10 +15,11 @@ namespace ReC.Client.Api
/// </summary>
/// <param name="http">The HTTP client used for requests.</param>
/// <param name="logger">An optional logger used to record API call outcomes.</param>
/// <param name="options">An optional set of client options. Defaults are used when omitted.</param>
#if NETFRAMEWORK
public ProfileApi(HttpClient http, ILogger logger = null) : base(http, "api/Profile", logger)
public ProfileApi(HttpClient http, ILogger logger = null, ReCClientOptions options = null) : base(http, "api/Profile", logger, options)
#else
public ProfileApi(HttpClient http, ILogger? logger = null) : base(http, "api/Profile", logger)
public ProfileApi(HttpClient http, ILogger? logger = null, ReCClientOptions? options = null) : base(http, "api/Profile", logger, options)
#endif
{
}

View File

@@ -15,10 +15,11 @@ namespace ReC.Client.Api
/// </summary>
/// <param name="http">The HTTP client used for requests.</param>
/// <param name="logger">An optional logger used to record API call outcomes.</param>
/// <param name="options">An optional set of client options. Defaults are used when omitted.</param>
#if NETFRAMEWORK
public RecActionApi(HttpClient http, ILogger logger = null) : base(http, "api/RecAction", logger)
public RecActionApi(HttpClient http, ILogger logger = null, ReCClientOptions options = null) : base(http, "api/RecAction", logger, options)
#else
public RecActionApi(HttpClient http, ILogger? logger = null) : base(http, "api/RecAction", logger)
public RecActionApi(HttpClient http, ILogger? logger = null, ReCClientOptions? options = null) : base(http, "api/RecAction", logger, options)
#endif
{
}
@@ -36,7 +37,7 @@ namespace ReC.Client.Api
using (content)
using (var resp = await Http.PostAsync($"{ResourcePath}/invoke/{profileId}", content, cancellationToken))
{
await ReCClientHelpers.HandleResponseAsync(resp, Logger, cancellationToken).ConfigureAwait(false);
await ReCClientHelpers.HandleResponseAsync(resp, Logger, Options.LogSuccessfulRequests, cancellationToken).ConfigureAwait(false);
}
}

View File

@@ -15,10 +15,11 @@ namespace ReC.Client.Api
/// </summary>
/// <param name="http">The HTTP client used for requests.</param>
/// <param name="logger">An optional logger used to record API call outcomes.</param>
/// <param name="options">An optional set of client options. Defaults are used when omitted.</param>
#if NETFRAMEWORK
public ResultApi(HttpClient http, ILogger logger = null) : base(http, "api/Result", logger)
public ResultApi(HttpClient http, ILogger logger = null, ReCClientOptions options = null) : base(http, "api/Result", logger, options)
#else
public ResultApi(HttpClient http, ILogger? logger = null) : base(http, "api/Result", logger)
public ResultApi(HttpClient http, ILogger? logger = null, ReCClientOptions? options = null) : base(http, "api/Result", logger, options)
#endif
{
}