RestProxy 1.2.2

dotnet add package RestProxy --version 1.2.2
                    
NuGet\Install-Package RestProxy -Version 1.2.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="RestProxy" Version="1.2.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="RestProxy" Version="1.2.2" />
                    
Directory.Packages.props
<PackageReference Include="RestProxy" />
                    
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 RestProxy --version 1.2.2
                    
#r "nuget: RestProxy, 1.2.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.
#:package RestProxy@1.2.2
                    
#: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=RestProxy&version=1.2.2
                    
Install as a Cake Addin
#tool nuget:?package=RestProxy&version=1.2.2
                    
Install as a Cake Tool

RestProxy

Proxy generator for .NET HTTP clients, which connect to an ASP.NET Core server.

Remarks

This package is still in development and definitely misses some features. If you would like to propose something you can create an issue on GitHub

Properties

As it is for now, RestProxyManager has 2 properties:

  • RequestTimeoutMilliseconds - request timeout in milliseconds
  • AllowUntrustedServerCertificate - whether to allow or not untrusted server's certificate

Usage

  1. Generate an interface representing your controller in ASP.NET Core server, but use types from ASPClientLib package (this allows support on all platforms because ASP.NET Core framework sometimes cannot be referenced). Controller interface must include at least RouteAttribute on the interface or actions and HttpMethodAttribute on all actions.

    Example:

    AuthenticationController ASP.NET Controller:

    [ApiController]
    [RouteApiController("[action]")]
    public class AuthenticationController(AuthService service) : ControllerBase
    {
        [HttpPost]
        [AllowAnonymous]
        public async Task<ActionResult<bool>> Login([FromBody] LoginRequest request)
        {
            var principal = service.TryGetPrincipal(request);
            if (principal == null)
            {
                return Unauthorized(false);
            }
    
            await HttpContext.SignInAsync(principal);
            return Ok(true);
        }
    }
    

    Note that in order for this controller to work, types (HttpPost, IActionResult, etc.) are from the ASP.NET Core framework.

    IAuthenticationController interface:

    [RouteApiController("[action]")]
    public interface IAuthenticationController
    {
        [HttpPost]
        Task<ActionResult<bool>> Login([FromBody] LoginRequest request);
    }
    

    Note that the interface uses types from the ASPClientLib package to mantain support on all client platforms

  2. Reference RestProxy and your controller interface (here IAutenticationController) in your client project.

  3. Create a new instance of the RestProxyManager class, providing base url of the server as the constructor parameter. Use the manager to get proxy and send request to the server.

      var manager = new RestProxyManager("https://localhost:5000/");
      var proxy = manager.GetProxy<IAuthenticationController>();
      bool result = (await proxy.Login(new LoginRequest(username, password))).Value;
    

    This construction automatically sets cookies when an appropriate header is received in response.

    1. Optionally you can configure authentication by providing asynchronous authentication method delegate in the constructor.

      var manager = new RestProxyManager("https://localhost:5000", authenticateActionAsync: AuthenticateAsync);
      var proxy = manager.GetProxy<ISimpleController>();
      var result = proxy.GetResult().Value; //Authentication happens on first 401 Unauthorized response
      

      This construction allows to configure header-based authentication.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.2.2 152 5/7/2025
1.2.1 193 3/3/2025
1.2.0 114 1/21/2025
1.1.3 157 11/30/2024
1.1.1 122 9/9/2024
1.1.0 112 8/6/2024
1.0.11 107 7/23/2024
1.0.10 121 7/17/2024
1.0.9 119 7/17/2024
1.0.8 120 7/17/2024
1.0.7 117 7/17/2024
1.0.6 128 6/28/2024
1.0.5 126 6/25/2024
1.0.4 119 6/25/2024
1.0.3 114 6/25/2024
1.0.2 121 6/24/2024
1.0.1 128 6/24/2024
1.0.0 119 6/24/2024

- Cleaned up package metadata