diff --git a/samples/Arbus.Network.Demo/GetAllOrdersApiEndpoint.cs b/samples/Arbus.Network.Demo/GetAllOrdersApiEndpoint.cs index 89d82c5..a4ecefe 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 Path => "https://example.com/api/v1/orders"; + public override string Uri => "https://example.com/api/v1/orders"; public override HttpMethod Method => HttpMethod.Get; } \ No newline at end of file diff --git a/src/Arbus.Network/Abstractions/ApiEndpoint.cs b/src/Arbus.Network/Abstractions/ApiEndpoint.cs index 98c7fbf..5cd1f24 100644 --- a/src/Arbus.Network/Abstractions/ApiEndpoint.cs +++ b/src/Arbus.Network/Abstractions/ApiEndpoint.cs @@ -9,7 +9,10 @@ public abstract class ApiEndpoint { private static readonly TimeSpan _defaultTimeout = TimeSpan.FromSeconds(10); - public abstract string Path { get; } + /// + /// Relative Uri if HttpClientContext.GetBaseUri() returns not null. Absolute Uri otherwise. + /// + public abstract string Uri { get; } public abstract HttpMethod Method { get; } @@ -31,13 +34,13 @@ public virtual HttpRequestMessage CreateRequest(Uri? baseUri) return request; } - private Uri CreateRequestUri(Uri? baseUrl) + private Uri CreateRequestUri(Uri? baseUri) { Uri uri; - if (baseUrl is null) - uri = new(Path); + if (baseUri is null) + uri = new(Uri); else - uri = new(baseUrl, Path); + uri = new(baseUri, Uri); return uri; } diff --git a/src/Arbus.Network/Abstractions/INativeHttpClient.cs b/src/Arbus.Network/Abstractions/INativeHttpClient.cs index 146208d..bc7742a 100644 --- a/src/Arbus.Network/Abstractions/INativeHttpClient.cs +++ b/src/Arbus.Network/Abstractions/INativeHttpClient.cs @@ -1,9 +1,8 @@ -namespace Arbus.Network.Abstractions +namespace Arbus.Network.Abstractions; + +public interface INativeHttpClient { - public interface INativeHttpClient - { - Task SendRequest(HttpRequestMessage request, CancellationToken cancellationToken, HttpCompletionOption httpCompletionOption = HttpCompletionOption.ResponseHeadersRead); - Task GetString(string url, TimeSpan? timeout = default); - Task GetString(Uri uri, TimeSpan? timeout = default); - } + Task SendRequest(HttpRequestMessage request, CancellationToken cancellationToken, HttpCompletionOption httpCompletionOption = HttpCompletionOption.ResponseHeadersRead); + Task GetString(string uri, TimeSpan? timeout = default); + Task GetString(Uri uri, TimeSpan? timeout = default); } \ No newline at end of file diff --git a/src/Arbus.Network/Arbus.Network.csproj b/src/Arbus.Network/Arbus.Network.csproj index fb3dd58..2ddf0f8 100644 --- a/src/Arbus.Network/Arbus.Network.csproj +++ b/src/Arbus.Network/Arbus.Network.csproj @@ -5,6 +5,8 @@ Latest enable enable + true + snupkg diff --git a/src/Arbus.Network/Implementations/HttpClientContext.cs b/src/Arbus.Network/Implementations/HttpClientContext.cs index 4311b19..3bc824f 100644 --- a/src/Arbus.Network/Implementations/HttpClientContext.cs +++ b/src/Arbus.Network/Implementations/HttpClientContext.cs @@ -52,12 +52,12 @@ public virtual async Task RunEndpointInternal(ApiEndpoint e private HttpRequestMessage CreateRequest(ApiEndpoint endpoint) { var request = endpoint.CreateRequest( - GetBaseUrl()); + GetBaseUri()); AddHeaders(request.Headers); return request; } - public virtual Uri? GetBaseUrl() => default; + public virtual Uri? GetBaseUri() => default; protected virtual void AddHeaders(HttpRequestHeaders headers) {