10

I'm creating a client for Rest API and I'm using the HttpClient class. My question is: should I use just one instance to handle all my requests? or should I create a new instance per request? Like:

using (var client = new HttpClient()) {
  ...
}

Is there any recommended practice?

dmorganb
  • 1,408
  • 16
  • 26
  • 2
    good explanation on when to reuse and when to use new HttpClient http://stackoverflow.com/questions/22560971/what-is-the-overhead-of-creating-a-new-httpclient-per-call-in-a-webapi-client – Aaron Hoffman Jul 04 '15 at 13:58

1 Answers1

8

You should try to reuse HttpClient instances as much as possible. The only reason to create a new instance is if you want to configure it differently.

Youssef Moussaoui
  • 12,187
  • 2
  • 41
  • 37