diff --git a/samples/Arbus.Network.Demo/GetAllOrdersApiEndpoint.cs b/samples/Arbus.Network.Demo/GetAllOrdersApiEndpoint.cs index a4ecefe..c1ce6c7 100644 --- a/samples/Arbus.Network.Demo/GetAllOrdersApiEndpoint.cs +++ b/samples/Arbus.Network.Demo/GetAllOrdersApiEndpoint.cs @@ -4,7 +4,7 @@ namespace Arbus.Network.Demo; public class GetAllOrdersApiEndpoint : ApiEndpoint { - public override string Uri => "https://example.com/api/v1/orders"; - - public override HttpMethod Method => HttpMethod.Get; + public GetAllOrdersApiEndpoint() : base(HttpMethod.Get, "https://example.com/api/v1/orders") + { + } } \ No newline at end of file diff --git a/src/Arbus.Network/Abstractions/ApiEndpoint.cs b/src/Arbus.Network/Abstractions/ApiEndpoint.cs index 5cd1f24..9e31864 100644 --- a/src/Arbus.Network/Abstractions/ApiEndpoint.cs +++ b/src/Arbus.Network/Abstractions/ApiEndpoint.cs @@ -12,14 +12,20 @@ public abstract class ApiEndpoint /// /// Relative Uri if HttpClientContext.GetBaseUri() returns not null. Absolute Uri otherwise. /// - public abstract string Uri { get; } + public string Uri { get; } - public abstract HttpMethod Method { get; } + public HttpMethod Method { get; } public virtual TimeSpan Timeout => _defaultTimeout; public CancellationToken? CancellationToken { get; set; } + public ApiEndpoint(HttpMethod method, string uri) + { + Method = method; + Uri = uri; + } + public virtual HttpRequestMessage CreateRequest(Uri? baseUri) { var requestUri = CreateRequestUri(baseUri); @@ -95,7 +101,13 @@ public virtual async Task HandleAnyResponse(HttpResponseMessage respo public abstract class ApiEndpoint : ApiEndpoint { - private static readonly TimeSpan _maxDeserializationTime = TimeSpan.FromSeconds(5); + private static readonly TimeSpan _defaultDeserializationTimeout = TimeSpan.FromSeconds(100); + + public virtual TimeSpan DeserializationTimeout => _defaultDeserializationTimeout; + + public ApiEndpoint(HttpMethod method, string uri) : base(method, uri) + { + } public virtual ValueTask GetResponse(HttpResponseMessage responseMessage) => FromJson(responseMessage.Content); @@ -104,7 +116,7 @@ public static async ValueTask FromJson(HttpContent content, CancellationTo { using var responseStream = await GetStream(content, cancellationToken).ConfigureAwait(false); - using var tokenSource = new CancellationTokenSource(_maxDeserializationTime); + using var tokenSource = new CancellationTokenSource(_defaultDeserializationTimeout); cancellationToken = tokenSource.Token; return await Deserialize(responseStream, cancellationToken.Value).ConfigureAwait(false)