HttpClientFactoryDemo
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
- TIME_WAIT
-
HttpClient
class -
SocketsHttpHandler
Class -
Make HTTP requests using
IHttpClientFactory
in ASP.NET Core - Use IHttpClientFactory to implement resilient HTTP requests
- IHttpClientFactoryinterface
-
HttpClientBuilderExtensions
Class -
Steve Gordon's blog posts on
HttpClient
[GitHub] [Twitter]-
HttpClient
Creation And Disposal Internals: Should I Dispose OfHttpClient
? -
Demystifying
HttpClient
Internals: SendAsync Flow ForHttpRequestMessage
-
Demystifying
HttpClient
Internals:HttpResponseMessage
-
HttpClient
Connection Pooling in .NET Core -
Using
HttpCompletionOption
To ImproveHttpClient
Performance In .NET -
Sending And Receiving JSON Using
HttpClient
WithSystem.Net.Http.Json
-
-
Steve Gordon's blog posts on
IHttpClientFactory
[GitHub] [Twitter]- HttpClientFactory in ASP.NET Core 2.1 (Part 1): An Introduction To HttpClientFactory
- HttpClientFactory In ASP.NET Core 2.1 (Part 2): Defining Named And Typed Clients
- HttpClientFactory In ASP.NET Core 2.1 (Part 3): Outgoing Request Middleware With Handlers
- HttpClientFactory In ASP.NET Core 2.1 (Part 4): Integrating With Polly For Transient Fault Handling
-
IHttpClientFactory
Patterns: Using Typed Clients From Singleton Services - HttpClientFactory In ASP.NET Core 2.1 (Part 5): Logging
-
Andrew Lock's blog posts on
IHttpClientFactory
[GitHub] [Twitter] - Damen Bod’s blog posts on
HttpClient
/IHttpClientFactory
[GitHub] [Twitter] - João Grassi [GitHub] [Twitter]