Last active
September 22, 2021 06:03
-
-
Save ByteDev/e5a5d656474186bcd05b23857c0b4e7c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
```csharp | |
public class CustomerApiClient : ICustomerApiClient | |
{ | |
private readonly HttpClient _httpClient; | |
private readonly CustomerApiClientConfig _config; | |
private readonly RequestFactory _requestFactory; | |
public CustomerApiClient(HttpClient httpClient, CustomerApiClientConfig config) | |
{ | |
_httpClient = httpClient ?? throw new ArgumentNullException(nameof(httpClient)); | |
_config = config ?? throw new ArgumentNullException(nameof(config)); | |
_requestFactory = new RequestFactory(config); | |
} | |
public async Task<SearchCustomerResponse> SearchAsync(SearchCustomerRequest request, CancellationToken cancellationToken = default) | |
{ | |
try | |
{ | |
var httpRequest = _requestFactory.Create(request, _config.SearchCustomerUri); | |
var httpResponse = await _httpClient.SendAsync(httpRequest, cancellationToken); | |
return await ResponseHandler.HandleAsync<SearchCustomerResponse>(httpResponse); | |
} | |
catch (Exception ex) | |
{ | |
throw new CustomerApiClientException("Error occurred while searching for customer.", ex); | |
} | |
} | |
// ... more methods for API operations | |
} | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment