From 5ebb3f72e32a038f11cf756389ee35b35a7ee46b Mon Sep 17 00:00:00 2001 From: TekH Date: Fri, 16 Jan 2026 11:29:54 +0100 Subject: [PATCH] Add CommonApi for generic HTTP object operations Introduced the CommonApi class in the ReC.Client.Api namespace to provide generic methods for creating, updating, and deleting objects via HTTP. The class uses an injected HttpClient and supports asynchronous operations with optional cancellation tokens. All methods serialize payloads to JSON using ReCClientHelpers.ToJsonContent. XML documentation was added for clarity. --- src/ReC.Client/Api/CommonApi.cs | 59 +++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/ReC.Client/Api/CommonApi.cs diff --git a/src/ReC.Client/Api/CommonApi.cs b/src/ReC.Client/Api/CommonApi.cs new file mode 100644 index 0000000..941c9e0 --- /dev/null +++ b/src/ReC.Client/Api/CommonApi.cs @@ -0,0 +1,59 @@ +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; + +namespace ReC.Client.Api +{ + /// + /// Provides access to common object endpoints. + /// + public class CommonApi + { + private readonly HttpClient _http; + + /// + /// Initializes a new instance of the class. + /// + /// The HTTP client used for requests. + public CommonApi(HttpClient http) + { + _http = http; + } + + /// + /// Creates an object. + /// + /// The payload type. + /// The payload to send. + /// A token to cancel the operation. + /// The HTTP response message. + public Task CreateObjectAsync(T procedure, CancellationToken cancel = default) + => _http.PostAsync("api/Common", ReCClientHelpers.ToJsonContent(procedure), cancel); + + /// + /// Updates an object. + /// + /// The payload type. + /// The payload to send. + /// A token to cancel the operation. + /// The HTTP response message. + public Task UpdateObjectAsync(T procedure, CancellationToken cancel = default) + => _http.PutAsync("api/Common", ReCClientHelpers.ToJsonContent(procedure), cancel); + + /// + /// Deletes objects. + /// + /// The payload type containing identifiers. + /// The payload to send. + /// A token to cancel the operation. + /// The HTTP response message. + public Task DeleteObjectAsync(T procedure, CancellationToken cancel = default) + { + var request = new HttpRequestMessage(HttpMethod.Delete, "api/Common") + { + Content = ReCClientHelpers.ToJsonContent(procedure) + }; + return _http.SendAsync(request, cancel); + } + } +}