This domain is established to be used for illustrative examples in documents. You may use this 46 | domain in examples without prior coordination or asking for permission.
47 | 48 |12 | ------- (1) ----------------- (2) ------- (3) ------- (4) -------------- (5) ~~~~~~~ 13 | | | --> | | --> | | --> | | --> | | --> ~ ~ 14 | | App | | ServiceClient | | RP1 | | RPn | | HttpClient | ~ Network ~ 15 | | | <-- | | <-- | | <-- | | <-- | | <-- ~ ~ 16 | ------- (8) ----------------- ------- (7) ------- (6) -------------- ~~~~~~~ 17 |18 | In this illustration, we're looking at an application that uses a ServiceClient. 19 | 20 | 1. First the application creates and gives an HTTP request ([WebResource](https://github.com/Azure/ms-rest-js/blob/master/lib/webResource.ts#L36)) object to the [ServiceClient's sendRequest()](https://github.com/Azure/ms-rest-js/blob/master/lib/serviceClient.ts#L149) method. When this [method](https://github.com/Azure/ms-rest-js/blob/master/lib/serviceClient.ts#L149) is called, the ServiceClient [creates the pipeline](https://github.com/Azure/ms-rest-js/blob/master/lib/serviceClient.ts#L167-L172) that is used to transform the request. This pipeline is a singly-linked list of [RequestPolicies](https://github.com/Azure/ms-rest-js/blob/master/lib/policies/requestPolicy.ts#L14) that ends with the ServiceClient's [HttpClient](https://github.com/Azure/ms-rest-js/blob/master/lib/httpClient.ts#L10). 21 | 2. Once the pipeline is created, the ServiceClient calls the first RequestPolicy's sendRequest() method with the HTTP request object provided to the ServiceClient's sendRequest() method. In the first RequestPolicy's sendRequest() method, the RequestPolicy either does something to the HTTP request (such as adding a [User-Agent header](https://github.com/Azure/ms-rest-js/blob/master/lib/policies/msRestUserAgentPolicy.ts#L20)) or does something because of the HTTP request (such as [emitting logs](https://github.com/Azure/ms-rest-js/blob/master/lib/policies/logPolicy.ts#L14)). 22 | 3. Each [RequestPolicy](https://github.com/Azure/ms-rest-js/blob/master/lib/policies/requestPolicy.ts#L14) has a [nextPolicy](https://github.com/Azure/ms-rest-js/blob/master/lib/policies/requestPolicy.ts#L19) property that points at the next RequestPolicy in the pipeline. When the current RequestPolicy is finished reacting to the HTTP request, it will call sendRequest() on the next policy in the pipeline. 23 | 4. This continues until the next RequestPolicy in the pipeline is actually the HttpClient (you may have noticed that the HttpClient actually extends the RequestPolicy interface, so it can be added as the last entry in the pipeline). 24 | 5. The HttpClient implementation now does whatever it needs to do to send the HTTP request across the network. Most likely the code that sends HTTP requests doesn't know how to handle a WebResource, so the HttpClient first needs to convert the WebResource HTTP request into the type that the real HTTP implementation knows how to deal with. Then it sends that converted request across the network. 25 | 6. Somehow the HttpClient will get an asynchronous response from the Network (either via callback or Promise). Either way, that response needs to be converted to a Promise