Add EndpointParamsApi for endpoint parameter operations
Introduced the EndpointParamsApi class in ReC.Client.Api to handle create, update, and delete operations for endpoint parameters via HTTP. Methods support generic payloads, cancellation tokens, and use JSON serialization helpers. Added necessary using directives for HTTP and threading.
This commit is contained in:
60
src/ReC.Client/Api/EndpointParamsApi.cs
Normal file
60
src/ReC.Client/Api/EndpointParamsApi.cs
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
using System.Net.Http;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ReC.Client.Api
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Provides access to endpoint parameter endpoints.
|
||||||
|
/// </summary>
|
||||||
|
public class EndpointParamsApi
|
||||||
|
{
|
||||||
|
private readonly HttpClient _http;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="EndpointParamsApi"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="http">The HTTP client used for requests.</param>
|
||||||
|
public EndpointParamsApi(HttpClient http)
|
||||||
|
{
|
||||||
|
_http = http;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates endpoint parameters.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">The payload type.</typeparam>
|
||||||
|
/// <param name="procedure">The payload to send.</param>
|
||||||
|
/// <param name="cancel">A token to cancel the operation.</param>
|
||||||
|
/// <returns>The HTTP response message.</returns>
|
||||||
|
public Task<HttpResponseMessage> CreateEndpointParamsAsync<T>(T procedure, CancellationToken cancel = default)
|
||||||
|
=> _http.PostAsync("api/EndpointParams", ReCClientHelpers.ToJsonContent(procedure), cancel);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Updates endpoint parameters.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">The payload type.</typeparam>
|
||||||
|
/// <param name="id">The parameter identifier.</param>
|
||||||
|
/// <param name="procedure">The payload to send.</param>
|
||||||
|
/// <param name="cancel">A token to cancel the operation.</param>
|
||||||
|
/// <returns>The HTTP response message.</returns>
|
||||||
|
public Task<HttpResponseMessage> UpdateEndpointParamsAsync<T>(long id, T procedure, CancellationToken cancel = default)
|
||||||
|
=> _http.PutAsync($"api/EndpointParams/{id}", ReCClientHelpers.ToJsonContent(procedure), cancel);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Deletes endpoint parameters.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">The payload type containing identifiers.</typeparam>
|
||||||
|
/// <param name="procedure">The payload to send.</param>
|
||||||
|
/// <param name="cancel">A token to cancel the operation.</param>
|
||||||
|
/// <returns>The HTTP response message.</returns>
|
||||||
|
public Task<HttpResponseMessage> DeleteEndpointParamsAsync<T>(T procedure, CancellationToken cancel = default)
|
||||||
|
{
|
||||||
|
var request = new HttpRequestMessage(HttpMethod.Delete, "api/EndpointParams")
|
||||||
|
{
|
||||||
|
Content = ReCClientHelpers.ToJsonContent(procedure)
|
||||||
|
};
|
||||||
|
return _http.SendAsync(request, cancel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user