First you need to create and initialize a HttpClient configured to accept JSON responses and also an Authentication Provider (using the Site ID and API Key obtained for your test merchant account).
The HttpClient Builder enables the below mandatory and optional configuration points. The only mandatory configuration point is AuthenticationProvider, the next configuration points are optional and let you have more control over the services.
-
AuthenticationProvider (Mandatory): use the Site ID and API Key obtained for your test merchant account;
-
Retry (Optional): You can configure the Counter and Exponential factor.
For more information, please visit: https://docs.microsoft.com/en-us/dotnet/standard/microservices-architecture/implement-resilient-applications/implement-http-call-retries-exponential-backoff-polly; -
CircuitBreaker (Optional):
For more information, please visit: https://docs.microsoft.com/en-us/azure/architecture/patterns/circuit-breaker;
https://docs.microsoft.com/en-us/dotnet/standard/microservices-architecture/implement-resilient-applications/implement-circuit-breaker-pattern;You can turn Resilience off by setting the property IsResilient to false!
You can create your own Resilience Policy by using Polly library: http://www.thepollyproject.org/.
-
Idempotence (Optional); Unique KeyGenerator. For more information, please visit: https://en.wikipedia.org/wiki/Idempotence.
-
TimeoutOperation (Optional): Gets or sets the number of milliseconds to wait before the request times out. TimeoutOperation property enables you to configure the number of retries and the timeout values for HTTP requests. In case the default values are not suitable for your use, you can change them;
-
Inner / Outer handlers (Optional): For more information, please visit: https://msdn.microsoft.com/en-us/library/system.net.http.delegatinghandler(v=vs.118).aspx.
Use HttpClient Builder to obtain a HttpClient Object, which you can use to initialize the services.
Please create only one HttpClient and use it for the entire life of your apllication. For more information, please visit: https://docs.microsoft.com/en-us/aspnet/web-api/overview/advanced/calling-a-web-api-from-a-net-client.