From 87d9769d9b0397deb93b5de418f0cc27d394f522 Mon Sep 17 00:00:00 2001 From: TekH Date: Fri, 16 Jan 2026 11:32:31 +0100 Subject: [PATCH] Add EndpointsApi for CRUD operations on endpoints Introduced EndpointsApi class in ReC.Client.Api to handle create, update, and delete operations for endpoint definitions via HTTP requests. Methods are generic, support cancellation tokens, and use a helper for JSON serialization of payloads. --- src/ReC.Client/Api/EndpointsApi.cs | 60 ++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/ReC.Client/Api/EndpointsApi.cs diff --git a/src/ReC.Client/Api/EndpointsApi.cs b/src/ReC.Client/Api/EndpointsApi.cs new file mode 100644 index 0000000..646a7f8 --- /dev/null +++ b/src/ReC.Client/Api/EndpointsApi.cs @@ -0,0 +1,60 @@ +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; + +namespace ReC.Client.Api +{ + /// + /// Provides access to endpoint definitions. + /// + public class EndpointsApi + { + private readonly HttpClient _http; + + /// + /// Initializes a new instance of the class. + /// + /// The HTTP client used for requests. + public EndpointsApi(HttpClient http) + { + _http = http; + } + + /// + /// Creates an endpoint. + /// + /// The payload type. + /// The payload to send. + /// A token to cancel the operation. + /// The HTTP response message. + public Task CreateEndpointAsync(T procedure, CancellationToken cancel = default) + => _http.PostAsync("api/Endpoints", ReCClientHelpers.ToJsonContent(procedure), cancel); + + /// + /// Updates an endpoint. + /// + /// The payload type. + /// The endpoint identifier. + /// The payload to send. + /// A token to cancel the operation. + /// The HTTP response message. + public Task UpdateEndpointAsync(long id, T procedure, CancellationToken cancel = default) + => _http.PutAsync($"api/Endpoints/{id}", ReCClientHelpers.ToJsonContent(procedure), cancel); + + /// + /// Deletes endpoints. + /// + /// The payload type containing identifiers. + /// The payload to send. + /// A token to cancel the operation. + /// The HTTP response message. + public Task DeleteEndpointAsync(T procedure, CancellationToken cancel = default) + { + var request = new HttpRequestMessage(HttpMethod.Delete, "api/Endpoints") + { + Content = ReCClientHelpers.ToJsonContent(procedure) + }; + return _http.SendAsync(request, cancel); + } + } +}