A type-safe REST library for .NET that automatically generates HTTP clients from interface definitions.
Refit is a type-safe REST library for .NET that automatically generates HTTP client implementations from interface definitions decorated with attributes. It solves the problem of writing repetitive boilerplate code for API calls by letting developers define API contracts as C# interfaces, which Refit then implements at compile time or runtime. This approach ensures compile-time safety and reduces errors when integrating with RESTful services.
.NET developers building applications that consume REST APIs, especially those working with ASP.NET Core, Xamarin, Blazor, or other .NET platforms who want type-safe, maintainable API client code.
Developers choose Refit because it dramatically reduces boilerplate, provides compile-time type safety for API interactions, and integrates seamlessly with modern .NET patterns like HttpClientFactory and dependency injection. Its inspiration from Retrofit brings a proven, declarative approach to .NET REST client development.
The automatic type-safe REST library for .NET Core, Xamarin and .NET. Heavily inspired by Square's Retrofit library, Refit turns your REST API into a live interface.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Refit generates HTTP client implementations at compile time from C# interfaces with attributes like [Get] and [Post], eliminating repetitive boilerplate code as shown in the basic IGitHubApi example.
By defining API contracts as interfaces, Refit ensures method signatures match endpoints, reducing runtime errors and improving developer experience through early validation.
Supports JSON (System.Text.Json and Newtonsoft.Json), XML, and form-urlencoded content via configurable serializers, allowing adaptation to various API formats as detailed in the Body Content section.
Seamlessly works with ASP.NET Core's HttpClientFactory for dependency injection and managed HTTP client lifecycles, demonstrated in the AddRefitClient setup examples.
Provides ApiResponse<T> wrappers and exceptions like ApiException for detailed error inspection, enabling robust error management with clear request/response separation.
Significant breaking changes in versions 6.x (switch to System.Text.Json) and 11.x (introduction of ApiRequestException) can disrupt existing codebases, requiring careful migration as noted in the README.
Setting up custom serializers, multipart uploads, or delegating handlers involves deep knowledge of RefitSettings and can be cumbersome for simple use cases, adding initial complexity.
Refit 6+ requires specific SDK versions (e.g., .NET SDK 5.0.100+) and PackageReference, imposing upgrade barriers for older projects or those using packages.config, as warned in the Breaking Changes section.
Key features like XML serialization and Newtonsoft.Json support require additional NuGet packages (Refit.Xml, Refit.Newtonsoft.Json), increasing dependency management overhead.