Comments on: HttpClient vs RestSharp – Which One to Use in .NET https://code-maze.com/httpclient-vs-restsharp/ Learn. Code. Succeed. Sun, 06 Nov 2022 21:24:55 +0000 hourly 1 https://wordpress.org/?v=6.7.5 By: Nehemiah Limo https://code-maze.com/httpclient-vs-restsharp/#comment-6883 Sun, 06 Nov 2022 21:24:55 +0000 https://drafts.code-maze.com/?p=72076#comment-6883 I love Restsharp for its automatic serialization/deserialization of JSON objects, and thanks for this article too. Please can you do one article of injecting Restsharp as a dependency inject on .NET 6? I find it challenging to set global configs, i.e. base_url to be set under the appsettings.json, please guide

]]>
By: Vladimir Pecanac https://code-maze.com/httpclient-vs-restsharp/#comment-6175 Sat, 30 Jul 2022 11:54:13 +0000 https://drafts.code-maze.com/?p=72076#comment-6175 In reply to Donnie Hale.

Thank you for the input Donnie. We’ve covered Refit as well.

]]>
By: Vladimir Pecanac https://code-maze.com/httpclient-vs-restsharp/#comment-6174 Sat, 30 Jul 2022 11:53:09 +0000 https://drafts.code-maze.com/?p=72076#comment-6174 In reply to Arthur Gor.

Flurl is a great library as well. We have an article covering Flurl too.

]]>
By: Marinko Spasojević https://code-maze.com/httpclient-vs-restsharp/#comment-6143 Tue, 26 Jul 2022 06:45:20 +0000 https://drafts.code-maze.com/?p=72076#comment-6143 In reply to Rob Slaney.

Thank you for the info. We are aware of how HttpClientFactory works and why it should be used, but for this article, we mainly wanted to compare HttpClient and RestSharp. But as you can see in the article, we had to mention HttpClientFactory and link to our article about it.

]]>
By: Rob Slaney https://code-maze.com/httpclient-vs-restsharp/#comment-6140 Tue, 26 Jul 2022 02:57:07 +0000 https://drafts.code-maze.com/?p=72076#comment-6140 The true magic of HttpClient is the underlying HttpClientHandler… this is what is expensive to create, and the lifetime/allocation of this is managed by the HttpClientFactory. HttpClient is, itself, only a wrapper around the handler.

Looking at the source for RestSharp, it creates a new handler for each instance of the RestClient. There is no object pooling or reuse of the handler.

I would strongly not recommend RestSharp as it will not scale.

Consider benchmarking using the HttpClientFactory, you should see a marked difference

]]>
By: Arthur Gor https://code-maze.com/httpclient-vs-restsharp/#comment-6090 Tue, 19 Jul 2022 15:37:47 +0000 https://drafts.code-maze.com/?p=72076#comment-6090 I stopped using RestSharp, instead my go to is Flurl

]]>
By: Ivan https://code-maze.com/httpclient-vs-restsharp/#comment-6037 Mon, 11 Jul 2022 21:10:03 +0000 https://drafts.code-maze.com/?p=72076#comment-6037 Why not compared with (de)serialization and httpClient since that is part of restsharp?

]]>
By: Donnie Hale https://code-maze.com/httpclient-vs-restsharp/#comment-6031 Fri, 08 Jul 2022 20:29:16 +0000 https://drafts.code-maze.com/?p=72076#comment-6031 I’ve been using Refit for the last 2+ years. https://github.com/reactiveui/refit

Can’t imagine not having it. And it leverages HttpClientFactory.

]]>
By: Marinko Spasojević https://code-maze.com/httpclient-vs-restsharp/#comment-6028 Fri, 08 Jul 2022 11:04:12 +0000 https://drafts.code-maze.com/?p=72076#comment-6028 In reply to James.

Hello James. I agree with you but this is not the topic of this article. As you can find in this article we’ve linked a Page with several HttpClient articles: https://code-maze.com/httpclient-with-asp-net-core-tutorial/ One of those is about HttpClientFactory and why and how you can use it. Whatsoever, we even linked that one in this article (Re-opening the connection is a costly process that can cause socket exhaustion. We can prevent this issue with HttpClientFactory to create and manage HttpClient instances.) That said, this article is mainly about comparison.

]]>
By: James https://code-maze.com/httpclient-vs-restsharp/#comment-6026 Fri, 08 Jul 2022 10:41:38 +0000 https://drafts.code-maze.com/?p=72076#comment-6026 I encourage you to use IHttpClientFactory instead of HttpClient to prevent socket exhaustion.

]]>