Skip to content

Commit

Permalink
Merge pull request #168 from hassanhabib/users/ElbekDeveloper/clients…
Browse files Browse the repository at this point in the history
…-bytes-get

CLIENTS: Get Byte Array
  • Loading branch information
hassanhabib authored Apr 1, 2024
2 parents fc69505 + a138dfe commit b995698
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions RESTFulSense/Clients/IRESTFulApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ ValueTask<T> GetContentAsync<T>(

ValueTask<Stream> GetContentStreamAsync(string relativeUrl);

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

ValueTask PostContentWithNoResponseAsync<T>(
string relativeUrl,
T content,
Expand Down
1 change: 1 addition & 0 deletions RESTFulSense/Clients/IRESTFulApiFactoryClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,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/Clients/RESTFulApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,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/Clients/RESTFulApiFactoryClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,19 @@ public async ValueTask<string> GetContentStringAsync(string relativeUrl) =>
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 b995698

Please # to comment.