Skip to content

HttpClient vs RestSharp: .NET 10, RestSharp 114.0.0, PutAsJsonAsync, LiveTests - #2286

Open
vladimir-pecanac-main wants to merge 1 commit into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/72080-httpclient-vs-restsharp
Open

vladimir-pecanac-main wants to merge 1 commit into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/72080-httpclient-vs-restsharp

Conversation

@vladimir-pecanac-main

Copy link
Copy Markdown
Collaborator

Sample update for the article "HttpClient vs RestSharp in C#: Which One to Use" (https://code-maze.com/httpclient-vs-restsharp/). Only this folder changes: dotnet-client-libraries/HttpClientVsRestSharp.

Changes:

  • Both projects move from net6.0 to net10.0. RestSharp 114.0.0 ships lib folders for net8.0, net9.0, net10.0, netstandard2.0, net471 and net48 only, so the bump and the retarget land together.
  • UpdateTodo_HttpClient uses PutAsJsonAsync, like the GET and POST benchmarks use the System.Net.Http.Json helpers. The System.Text and System.Text.Json usings it no longer needs are removed.
  • The two static fields use target-typed new(), and BaseAddress is set in the HttpClient initializer, so the TodoBenchmark constructor is gone.
  • Tests.cs is renamed to LiveTests.cs (class LiveTests). Every test calls jsonplaceholder.typicode.com, and the CI filter FullyQualifiedName!~Live keeps live tests out of CI.
  • New tests for the article's side-by-side table: GetFromJsonAsync, ExecuteGetAsync with IsSuccessful, a 404 on both clients (EnsureSuccessStatusCode throws HttpRequestException; ExecuteGetAsync reports IsSuccessful false and StatusCode NotFound without throwing), HttpClient.Send and RestClient.Get.

Package versions, re-queried on NuGet on 2026-10-11 (latest stable):

  • RestSharp 114.0.0 (from 108.0.1)
  • BenchmarkDotNet 0.15.8 (from 0.13.1)
  • Microsoft.NET.Test.Sdk 18.10.1 (from 16.11.0)
  • xunit 2.9.3 (from 2.4.1)
  • xunit.runner.visualstudio 4.0.1 (from 2.4.3)
  • coverlet.collector 10.1.0 (from 3.1.0)

Verified locally on .NET SDK 10.0.302, runtime 10.0.10: dotnet build -c Release, 0 warnings, 0 errors; dotnet test, 14 passed, 0 failed; dotnet list package --vulnerable --include-transitive, no vulnerable packages.

…LiveTests

- Retarget both projects from net6.0 to net10.0 (RestSharp 114.0.0 ships no net6.0 or net7.0 asset)
- RestSharp 108.0.1 to 114.0.0, BenchmarkDotNet 0.13.1 to 0.15.8
- Tests: Microsoft.NET.Test.Sdk 18.10.1, xunit 2.9.3, xunit.runner.visualstudio 4.0.1, coverlet.collector 10.1.0
- UpdateTodo_HttpClient uses PutAsJsonAsync; unused System.Text and System.Text.Json usings removed
- Field initializers are target-typed and set BaseAddress, so the constructor is gone
- Tests renamed to LiveTests (they call jsonplaceholder.typicode.com), with tests for
  GetFromJsonAsync, ExecuteGetAsync, a 404 on both clients, HttpClient.Send and RestClient.Get<T>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant