XxxClient Object, Pipelines, and Policies
We construct some XxxClient objects so that our application can make a call when we are using our client libraries. When you create an XxxClient, we pass it to the URL of the service endpoint, the credential we wish to use to authenticate with the service and some options. The credential and options are used to create an HTTP pipeline.
This HTTP pipeline adds behavior to an HTTP response and request. Each behavior is called a policy like a retry policy, a logging policy, etc. So, we have an authentication policy which applies our credential. Each policy can modify or change an HTTP request’s query parameter, and headers before the requests are sent over the wire.
Not all policy objects modify or change an HTTP request. By performing operations such as logging, retry policies, timeouts, and downloading of response payloads, some policies simply impact the flow of a request or response.
The order of the policies is important because each policy changes the request and then forward that changed request to the other policy. For example, where policy between the XxxClient’s method and the retry policy executes once per logical service operation. On the other hand, the policy between the retry policy and the transport policy executes once per physical network operation.
We can implement our own policies for things like client-side caching, circuit breakers, mocking, fault injection, and much more.