HttpClientFactoryDemo icon indicating copy to clipboard operation
HttpClientFactoryDemo copied to clipboard

Demo of IHttpClientFactory

HttpClient and HttpClient factory demo

To access the demos, checkout the respective tag.

git checkout tags/single-use-httpclient --force --quiet

The demo accesses https://bing.com/ and https://api.github.com/. Due to the high intensity of the requests, those websites might (they will!) throttle the requests.

To monitor for TIME_WAIT connections to these destinations, use the following PowerShell command:

while ($true) { (Get-NetTCPConnection -RemoteAddress '13.107.21.200','204.79.197.200','140.82.118.6' -State TimeWait -ErrorAction Ignore).Count } 

Single use HttpClient

tag: single-use-httpclient

This demo uses a new instance of HttpClient each time it's used.

Single use HttpClient with connection close

tag: single-use-httpclient-connection-close

This demo uses a new instance of HttpClient each time it's used with ConnectionClose set to true.

Singleton HttpClient

tag: single-use-httpclient-connection-close

This demo uses a singleton instance of HttpClient for every use.

Single use HttpClient with singleton HttpClientHandler

tag: single-use-httpclient-singleton-httpclienthandler

This demo uses a singleton instance of HttpClientHandler in instances of HttpClient for one-time use.

Use HttpClient factory

tag: httpclientfactory

This demo uses the implmentation of IHttpHandlerFactory to create instances of HttpClient for one-time use.

Use HttpClient factory with named clients

tag: httpclientfactory-named-httpclient

This demo uses the implmentation of IHttpHandlerFactory to create instances of HttpClient for one-time use using named definitions.

Use HttpClient factory with typed clients

tag: httpclientfactory-typed-client

This demo uses the implmentation of IHttpHandlerFactory to create instances of HttpClient for one-time use using typed clients.

Use HttpClient factory with custom primary handler

tag: httpclientfactory-socketshttphandler

This demo uses the implmentation of IHttpHandlerFactory to create instances of HttpClient for one-time use using a custom primary handler (SocketsHttpHandler).

Use HttpClient factory with policies

tag: httpclientfactory-polly

This demo uses the implmentation of IHttpHandlerFactory to create instances of HttpClient for one-time use using policies provided by Polly.

Resources