Twelve Days of .NET: Day 11: HttpClient

This post is part of my 12 Days of .NET series. This is a (not terribly ambitious) series of posts on .NET topics that came up while I was working on a recent C# Web API project.

The standard way to call a REST API in .NET is to use HttpClient. I don’t think HttpClient existed yet when I first needed to interact with REST web services, several years ago. I remember using something called RestSharp, which, I now see, still exists and appears to still be actively maintained, with some fairly recent commits. (Including several on Christmas Eve!)

Here’s a good overview article on how to use HttpClient. And here’s an important blog post on how NOT to use it.

And here’s another interesting blog post, that goes a lot deeper into disposal and finalization with regard to HttpClient. (I have to admin that I’ve only skimmed this post. But I should really read it.)

One surprising thing I discovered while working on my current project is that HttpClient doesn’t have a PatchAsync method. The workaround is pretty easy, and can be found in that linked GitHub issue, and in a number of StackOverflow answers.

One thought on “Twelve Days of .NET: Day 11: HttpClient”

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.