RestProxy 1.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package RestProxy --version 1.0.2
                    
NuGet\Install-Package RestProxy -Version 1.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="RestProxy" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="RestProxy" Version="1.0.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.0.2
                    
#r "nuget: RestProxy, 1.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.
#:package RestProxy@1.0.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.0.2
                    
Install as a Cake Addin
#tool nuget:?package=RestProxy&version=1.0.2
                    
Install as a Cake Tool

RestProxy

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

https://github.com/ja3cob/RestProxy

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

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;
    
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.  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. 
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 218 5/7/2025
1.2.1 239 3/3/2025
1.2.0 165 1/21/2025
1.1.3 210 11/30/2024
1.1.1 167 9/9/2024
1.1.0 158 8/6/2024
1.0.11 152 7/23/2024
1.0.10 170 7/17/2024
1.0.9 166 7/17/2024
1.0.8 174 7/17/2024
1.0.7 162 7/17/2024
1.0.6 174 6/28/2024
1.0.5 181 6/25/2024
1.0.4 165 6/25/2024
1.0.3 161 6/25/2024
1.0.2 166 6/24/2024
1.0.1 177 6/24/2024
1.0.0 168 6/24/2024