Refit.Reflection 15.2.0

Prefix Reserved

Requires NuGet 2.12 or higher.

dotnet add package Refit.Reflection --version 15.2.0
                    
NuGet\Install-Package Refit.Reflection -Version 15.2.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Refit.Reflection" Version="15.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Refit.Reflection" Version="15.2.0" />
                    
Directory.Packages.props
<PackageReference Include="Refit.Reflection" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Refit.Reflection --version 15.2.0
                    
#r "nuget: Refit.Reflection, 15.2.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Refit.Reflection@15.2.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Refit.Reflection&version=15.2.0
                    
Install as a Cake Addin
#tool nuget:?package=Refit.Reflection&version=15.2.0
                    
Install as a Cake Tool

Refit

Refit: The automatic type-safe REST library for modern .NET

Build codecov

Refit Refit.HttpClientFactory Refit.Newtonsoft.Json Refit.Testing
NuGet NuGet NuGet NuGet NuGet

Refit is a library heavily inspired by Square's Retrofit library, and it turns your REST API into a live interface:

public interface IGitHubApi
{
    [Get("/users/{user}")]
    Task<User> GetUser(string user);
}

The RestService class generates an implementation of IGitHubApi that uses HttpClient to make its calls:

var gitHubApi = RestService.For<IGitHubApi>("https://api.github.com");
var octocat = await gitHubApi.GetUser("octocat");

.NET supports registering Refit clients via HttpClientFactory:

services
    .AddRefitClient<IGitHubApi>()
    .ConfigureHttpClient(c => c.BaseAddress = new Uri("https://api.github.com"));

To test the clients you build with Refit, the Refit.Testing package lets you stub responses and verify requests with a declarative route table — see Testing your Refit clients.

Table of Contents

Sponsors

Refit is sponsored by the following:

lombiq logojetbrains logoclaude logo

Where does this work?

Refit currently supports the following platforms and modern .NET targets:

  • WinUI
  • Desktop .NET Framework 4.6.2+
  • .NET 8 / 9 / 10 / 11
  • Blazor
  • Uno Platform

SDK Requirements

The source generator ships inside the Refit package as a Roslyn analyzer, so it is your build tools, not your target framework, that decide whether you get generated clients:

Requirement Minimum
Roslyn (C# compiler) 4.8
Visual Studio