Skip to content

Commit

Permalink
CLIENTS: Get Byte Array
Browse files Browse the repository at this point in the history
  • Loading branch information
ElbekDeveloper committed Apr 1, 2024
1 parent b995698 commit 24ee3f8
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion RESTFulSense.WebAssembly/Clients/IRESTFulApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ ValueTask<T> GetContentAsync<T>(
Func<string, ValueTask<T>> deserializationFunction = null);

ValueTask<string> GetContentStringAsync(string relativeUrl);

ValueTask<Stream> GetContentStreamAsync(string relativeUrl);
ValueTask<byte[]> GetContentByteArrayAsync(string relativeUrl);

ValueTask PostContentWithNoResponseAsync<T>(
string relativeUrl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ ValueTask<T> GetContentAsync<T>(

ValueTask<string> GetContentStringAsync(string relativeUrl);
ValueTask<Stream> GetContentStreamAsync(string relativeUrl);
ValueTask<byte[]> GetContentByteArrayAsync(string relativeUrl);

ValueTask PostContentWithNoResponseAsync<T>(
string relativeUrl,
Expand Down
13 changes: 13 additions & 0 deletions RESTFulSense.WebAssembly/Clients/RESTFulApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,19 @@ public async ValueTask<string> GetContentStringAsync(string relativeUrl) =>
public async ValueTask<Stream> GetContentStreamAsync(string relativeUrl) =>
await GetStreamAsync(relativeUrl);

public async ValueTask<byte[]> 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<T>(
string relativeUrl,
T content,
Expand Down
13 changes: 13 additions & 0 deletions RESTFulSense.WebAssembly/Clients/RESTFulApiFactoryClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,19 @@ await ConvertToHttpContent(
public async ValueTask<Stream> GetContentStreamAsync(string relativeUrl) =>
await this.httpClient.GetStreamAsync(relativeUrl);

public async ValueTask<byte[]> 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<T>(
string relativeUrl,
T content,
Expand Down

0 comments on commit 24ee3f8

Please sign in to comment.