RestEaseInterface 0.0.2
dotnet add package RestEaseInterface --version 0.0.2
NuGet\Install-Package RestEaseInterface -Version 0.0.2
<PackageReference Include="RestEaseInterface" Version="0.0.2" />
paket add RestEaseInterface --version 0.0.2
#r "nuget: RestEaseInterface, 0.0.2"
// Install RestEaseInterface as a Cake Addin
#addin nuget:?package=RestEaseInterface&version=0.0.2
// Install RestEaseInterface as a Cake Tool
#tool nuget:?package=RestEaseInterface&version=0.0.2
RestEase + RestEaseInterface =
RestEaseInterface is designed to enable fast, seamless, and strongly-typed communication between .NET applications using REST. It is built on top of RestEase, allowing you to create REST clients using a configured interface. RestEaseInterface complements this by generating corresponding endpoints with minimal APIs based on the same interface to handle incoming requests. Swagger supported.
Implementation
Follow these steps to implement RestEaseInterface:
Create an Interface: Follow the RestEase documentation to design an interface. This interface should be accessible to both the client and server, as shown in the example project.
Client Initialization: On the client side, initialize the interface either directly or using HttpClientFactory.
Server-Side Implementation: On the server side (AspNetCore is required), create a class that implements the configured interface. This class will contain your business logic. Note: Do not create multiple classes for a single configured RestEase interface.
Server-Side Configuration in Startup/Program.cs:
- In the
IServiceCollection
, use.UseRestEaseApiInterface()
. This method searches for configured interfaces and classes at startup using reflection. - In the
IServiceProvider
, use.AddRestEaseInterface()
. This dynamically constructs minimal APIs based on these interfaces.
- In the
Example
Shared code - available on server and client
using RestEase;
namespace RestEaseInterface.Example.Shared;
public interface IWeatherForecastController
{
[Get("GetWeatherForecast")]
IEnumerable<WeatherForecast> Get();
}
public class WeatherForecast
{
public DateOnly Date { get; set; }
public int TemperatureC { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
public string? Summary { get; set; }
}
Server code - Program.cs
using RestEaseInterface;
using RestEaseInterface.Swagger;
var builder = WebApplication.CreateBuilder(args);
// [...]
//Swagger implementation (optional)
builder.Services.AddSwaggerGen(x =>
{
x.EnableAnnotations();
x.DocumentFilter<RestEaseInterfaceSwaggerDocumentFilter>();
});
//RestEase implementation
builder.Services.AddRestEaseInterface();
var app = builder.Build();
// [...]
//RestEase implementation
app.UseRestEaseInterface();
Client code - Program.cs
using RestEase;
using RestEaseInterface.Example.Shared;
IWeatherForecastController api = RestClient.For<IWeatherForecastController>("http://localhost:<port>");
WeatherForecast[] weatherInfos = api.Get().Result.ToArray();
foreach (var weatherInfo in weatherInfos) {
Console.WriteLine($"Date: {weatherInfo.Date}. Summary: {weatherInfo.Summary}."
+ $"Temp°C: {weatherInfo.TemperatureC}. Temp-Fahrenheit: {weatherInfo.TemperatureF}");
}
Console.ReadLine();
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net8.0
- Newtonsoft.Json (>= 13.0.3)
- RestEase (>= 1.6.4)
- Swashbuckle.AspNetCore (>= 6.5.0)
- Swashbuckle.AspNetCore.Annotations (>= 6.5.0)
- Swashbuckle.AspNetCore.Filters (>= 7.0.12)
- Swashbuckle.AspNetCore.SwaggerGen (>= 6.5.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on RestEaseInterface:
Package | Downloads |
---|---|
RestEaseInterface.Swagger
Effortlessly link your .NET client and server with a single interface. This easy-to-use library, built upon RestEase, allows you to define your REST API in one place, ensuring seamless and strong-typed communication. Quick setup, minimal code, and optional Swagger integration for a streamlined development experience. |
GitHub repositories
This package is not used by any popular GitHub repositories.