Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLIENTS: Execute Any API Call w/ Validations #173

Merged
merged 2 commits into from
Apr 28, 2024

Conversation

hassanhabib
Copy link
Owner

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

  • PATCH
  • FORM
  • HEAD
  • OPTIONS

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.

ShouldExecuteHttpCallAsync -> PASS
ShouldExecuteHttpCallAsync -> PASS
ShouldExecuteHttpCallAsync -> PASS
@hassanhabib hassanhabib merged commit dc9a0f6 into master Apr 28, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant