diff --git a/dotnet-client-libraries/Refit/RefitLibrary/IUsersClient.cs b/dotnet-client-libraries/Refit/RefitLibrary/IUsersClient.cs index 26b1f04a55..331a84f765 100644 --- a/dotnet-client-libraries/Refit/RefitLibrary/IUsersClient.cs +++ b/dotnet-client-libraries/Refit/RefitLibrary/IUsersClient.cs @@ -2,14 +2,21 @@ namespace RefitLibrary; +[Headers("User-Agent: CodeMaze-Sample")] public interface IUsersClient { [Get("/users")] Task> GetAll(); + [Get("/users")] + Task> GetAll([Query] string? name, CancellationToken token); + [Get("/users/{id}")] Task GetUser(int id); + [Get("/users/{id}")] + Task> GetUserResponse(int id); + [Post("/users")] Task CreateUser([Body] User user); diff --git a/dotnet-client-libraries/Refit/RefitLibrary/Program.cs b/dotnet-client-libraries/Refit/RefitLibrary/Program.cs index 3aca13dd13..3f2f042fd6 100644 --- a/dotnet-client-libraries/Refit/RefitLibrary/Program.cs +++ b/dotnet-client-libraries/Refit/RefitLibrary/Program.cs @@ -7,7 +7,7 @@ .ConfigureServices((_, services) => { services - .AddRefitClient() + .AddRefitGeneratedClient() .ConfigureHttpClient(c => c.BaseAddress = new Uri("https://jsonplaceholder.typicode.com/")); }).Build(); @@ -33,4 +33,9 @@ await usersClient.DeleteUser(userId); Console.WriteLine("User deleted"); +var response = await usersClient.GetUserResponse(999); + +if (!response.IsSuccessStatusCode) + Console.WriteLine($"Failed: {response.StatusCode}"); + public partial class Program { } diff --git a/dotnet-client-libraries/Refit/RefitLibrary/RefitLibrary.csproj b/dotnet-client-libraries/Refit/RefitLibrary/RefitLibrary.csproj index a9865d1dcf..412733dd58 100644 --- a/dotnet-client-libraries/Refit/RefitLibrary/RefitLibrary.csproj +++ b/dotnet-client-libraries/Refit/RefitLibrary/RefitLibrary.csproj @@ -2,15 +2,15 @@ Exe - net6.0 + net10.0 enable enable - - - + + + diff --git a/dotnet-client-libraries/Refit/Tests/Tests.csproj b/dotnet-client-libraries/Refit/Tests/Tests.csproj index dca4934952..67f2b08fc4 100644 --- a/dotnet-client-libraries/Refit/Tests/Tests.csproj +++ b/dotnet-client-libraries/Refit/Tests/Tests.csproj @@ -1,17 +1,17 @@ - net6.0 + net10.0 enable false - - - - + + + + runtime; build; native; contentfiles; analyzers; buildtransitive