Share:

[Redirect] How you should (not) use HttpClient

By João Antunes

- 1 minutes read - 94 words

(The redirect tag in the title means this post is just a share of another post)

So, how do you use the HttpClient (.NET)? Like this?

1
2
3
4
5
using (var client = new HttpClient())
{
    var result = await client.GetAsync("http://xpto.com/api/stuff");
    //...
}

Well, so do I. And it’s wrong.

Check out this article that tells you all about why. tl;dr Use a singleton instance. Oh, and after that one, this is also a good (important) related read. (You’ll see that this second article makes my tl;dr a bit too short)

Cyaz

Categories: dotnet redirect
Tags: dotnet httpclient

Share:

comments powered by Disqus