diff --git a/RESTFulSense.WebAssembly/Clients/IRESTFulApiClient.cs b/RESTFulSense.WebAssembly/Clients/IRESTFulApiClient.cs index 5ad7eb0..e52e3b7 100644 --- a/RESTFulSense.WebAssembly/Clients/IRESTFulApiClient.cs +++ b/RESTFulSense.WebAssembly/Clients/IRESTFulApiClient.cs @@ -23,8 +23,8 @@ ValueTask GetContentAsync( Func> deserializationFunction = null); ValueTask GetContentStringAsync(string relativeUrl); - ValueTask GetContentStreamAsync(string relativeUrl); + ValueTask GetContentByteArrayAsync(string relativeUrl); ValueTask PostContentWithNoResponseAsync( string relativeUrl, diff --git a/RESTFulSense.WebAssembly/Clients/IRESTFulApiFactoryClient.cs b/RESTFulSense.WebAssembly/Clients/IRESTFulApiFactoryClient.cs index 1effccd..b26636e 100644 --- a/RESTFulSense.WebAssembly/Clients/IRESTFulApiFactoryClient.cs +++ b/RESTFulSense.WebAssembly/Clients/IRESTFulApiFactoryClient.cs @@ -24,6 +24,7 @@ ValueTask GetContentAsync( ValueTask GetContentStringAsync(string relativeUrl); ValueTask GetContentStreamAsync(string relativeUrl); + ValueTask GetContentByteArrayAsync(string relativeUrl); ValueTask PostContentWithNoResponseAsync( string relativeUrl, diff --git a/RESTFulSense.WebAssembly/Clients/RESTFulApiClient.cs b/RESTFulSense.WebAssembly/Clients/RESTFulApiClient.cs index 91fb139..88952c5 100644 --- a/RESTFulSense.WebAssembly/Clients/RESTFulApiClient.cs +++ b/RESTFulSense.WebAssembly/Clients/RESTFulApiClient.cs @@ -45,6 +45,19 @@ public async ValueTask GetContentStringAsync(string relativeUrl) => public async ValueTask GetContentStreamAsync(string relativeUrl) => await GetStreamAsync(relativeUrl); + public async ValueTask GetContentByteArrayAsync(string relativeUrl) + { + HttpResponseMessage responseMessage = + await GetAsync(relativeUrl); + + if (responseMessage.IsSuccessStatusCode is false) + { + await ValidationService.ValidateHttpResponseAsync(responseMessage); + } + + return await responseMessage.Content.ReadAsByteArrayAsync(); + } + public async ValueTask PostContentWithNoResponseAsync( string relativeUrl, T content, diff --git a/RESTFulSense.WebAssembly/Clients/RESTFulApiFactoryClient.cs b/RESTFulSense.WebAssembly/Clients/RESTFulApiFactoryClient.cs index cfa6ad4..7565d40 100644 --- a/RESTFulSense.WebAssembly/Clients/RESTFulApiFactoryClient.cs +++ b/RESTFulSense.WebAssembly/Clients/RESTFulApiFactoryClient.cs @@ -80,6 +80,19 @@ await ConvertToHttpContent( public async ValueTask GetContentStreamAsync(string relativeUrl) => await this.httpClient.GetStreamAsync(relativeUrl); + public async ValueTask GetContentByteArrayAsync(string relativeUrl) + { + HttpResponseMessage responseMessage = + await this.httpClient.GetAsync(relativeUrl); + + if (responseMessage.IsSuccessStatusCode is false) + { + await ValidationService.ValidateHttpResponseAsync(responseMessage); + } + + return await responseMessage.Content.ReadAsByteArrayAsync(); + } + public async ValueTask PostContentWithNoResponseAsync( string relativeUrl, T content,