Skip to content

Refit: retarget net10.0, Refit 15.2.0, AddRefitGeneratedClient, error-handling and headers samples - #2136

Merged
vladimir-pecanac-main merged 3 commits into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/71475-using-refit-to-consume-apis-in-csharp
Aug 24, 2026
Merged

Refit: retarget net10.0, Refit 15.2.0, AddRefitGeneratedClient, error-handling and headers samples#2136
vladimir-pecanac-main merged 3 commits into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/71475-using-refit-to-consume-apis-in-csharp

Conversation

@vladimir-pecanac-main

Copy link
Copy Markdown
Collaborator

Updates the dotnet-client-libraries/Refit sample for the refresh of Using Refit to Consume APIs in C#.

Retarget and pins

  • RefitLibrary and Tests retargeted net6.0 -> net10.0
  • Refit and Refit.HttpClientFactory 6.3.2 -> 15.2.0
  • Microsoft.Extensions.Hosting 6.0.1 -> 10.0.0
  • Microsoft.AspNetCore.Mvc.Testing 6.0.5 -> 10.0.0
  • Microsoft.NET.Test.Sdk 16.11.0 -> 17.11.1
  • xunit, xunit.runner.visualstudio and coverlet.collector left untouched: the test project builds and passes on net10.0 with the versions it already had

Registration path

On Refit 15.x services.AddRefitClient<IUsersClient>() compiles and then throws System.NotSupportedException at DI resolution, because the reflection request builder moved into the opt-in Refit.Reflection package in v14. Program.cs now registers with AddRefitGeneratedClient<IUsersClient>(), which resolves the source-generated implementation and needs no extra package. RestService.For<T> is unaffected, which is why the integration tests passed while the console entry point did not.

New sample code

  • IUsersClient gains Task<ApiResponse<User>> GetUserResponse(int id) for the return-type-instead-of-catching style
  • a GetAll([Query] string? name, CancellationToken token) overload and an interface-level [Headers] attribute
  • Program.cs shows the ApiResponse call site

Verified on SDK 10.0.302 / runtime 10.0.10: dotnet build -c Release 0 errors 0 warnings; dotnet test -c Release 4/4 passed; dotnet run completes the full CRUD sequence against the live jsonplaceholder API and prints Failed: NotFound for the 404 response case.

…-handling and headers samples

- RefitLibrary and Tests retargeted net6.0 -> net10.0
- Refit and Refit.HttpClientFactory 6.3.2 -> 15.2.0
- Microsoft.Extensions.Hosting 6.0.1 -> 10.0.0
- Microsoft.AspNetCore.Mvc.Testing 6.0.5 -> 10.0.0
- Microsoft.NET.Test.Sdk 16.11.0 -> 17.11.1
- Program.cs registers with AddRefitGeneratedClient<IUsersClient>(); on Refit 15.x
  AddRefitClient<T>() throws NotSupportedException without the opt-in
  Refit.Reflection package
- IUsersClient gains an ApiResponse<User> endpoint, a query-string plus
  CancellationToken overload, and an interface-level [Headers] attribute;
  Program.cs shows the ApiResponse call site
@vladimir-pecanac-main
vladimir-pecanac-main merged commit 7935946 into CodeMazeBlog:main Aug 24, 2026
3 checks passed
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