RestEaseInterface 0.0.2

dotnet add package RestEaseInterface --version 0.0.2
NuGet\Install-Package RestEaseInterface -Version 0.0.2
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="RestEaseInterface" Version="0.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add RestEaseInterface --version 0.0.2
#r "nuget: RestEaseInterface, 0.0.2"
#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.
// 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 = Heart

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:

  1. 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.

  2. Client Initialization: On the client side, initialize the interface either directly or using HttpClientFactory.

  3. 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.

  4. 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.

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.

Version Downloads Last updated
0.0.2 319 12/10/2023
0.0.1 97 11/29/2023