hassanhabib / RESTFulSense

A RESTFul operations client that serializes responses and throws meaningful exceptions for >= 400 status codes.
https://www.restfulsense.com
237 stars 51 forks source link

CLIENTS: Execute Any API Call w/ Validations #173

Closed hassanhabib closed 6 months ago

hassanhabib commented 6 months ago

There are several cases where RESTFulSense doesn't yet implement a functionality that HttpClient already offers. Here are some examples:

amongst many others.

This implementation enables any http call to be passed onto a ExecuteCallAsync function that validates the HttpResponseMessage and throws a proper exception if found.

Here's an example:

var httpClient = new HttpClient();
httpClient.BaseAddress = 
httpClient.BaseAddress = new Uri("hassanhabib.com");

HttpMessageResponse =
    await this.restfulApiClient.ExecuteHttpCallAsync(
        httpClient.GetAsync("/tests"));

The above ExecuteHttpCallAsync will take care of handling any HttpResponseException and convert the response if erroneous into a meaningful exception like HttpBadRequestException and so on.