Sun.Core.ApisixClient 1.0.0

dotnet add package Sun.Core.ApisixClient --version 1.0.0                
NuGet\Install-Package Sun.Core.ApisixClient -Version 1.0.0                
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="Sun.Core.ApisixClient" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Sun.Core.ApisixClient --version 1.0.0                
#r "nuget: Sun.Core.ApisixClient, 1.0.0"                
#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 Sun.Core.ApisixClient as a Cake Addin
#addin nuget:?package=Sun.Core.ApisixClient&version=1.0.0

// Install Sun.Core.ApisixClient as a Cake Tool
#tool nuget:?package=Sun.Core.ApisixClient&version=1.0.0                

Đăng ký dịch vụ Trong file Program.cs (hoặc Startup.cs nếu bạn đang sử dụng), đăng ký ApisixClient và ApisixHelpers:

using Sun.Core.ApisixClient; using Sun.Core.ApisixClient.Helpers;

public class Program { public static void Main(string[] args) { var builder = WebApplication.CreateBuilder(args);

    // Đăng ký ApisixClient
    builder.Services.AddApisixClient(builder.Configuration);

    // Đăng ký ApisixHelpers
    builder.Services.AddTransient<ApisixHelpers>();

    // Các dịch vụ khác...

    var app = builder.Build();

    // Cấu hình middleware...

    app.Run();
}

}


Sử dụng trong Controller

using Microsoft.AspNetCore.Mvc; using Sun.Core.ApisixClient.Helpers; using Sun.Core.ApisixClient.Models;

[ApiController] [Route("api/[controller]")] public class ApisixManagementController : ControllerBase { private readonly ApisixHelpers _apisixHelpers;

public ApisixManagementController(ApisixHelpers apisixHelpers)
{
    _apisixHelpers = apisixHelpers;
}

[HttpPost("routes")]
public async Task<IActionResult> CreateRoute(string path, string upstreamUrl)
{
    var result = await _apisixHelpers.CreateSimpleRoute(path, upstreamUrl);
    if (result)
    {
        return Ok("Route created successfully");
    }
    return BadRequest("Failed to create route");
}

[HttpPost("routes/{routeId}/cors")]
public async Task<IActionResult> AddCorsToRoute(string routeId)
{
    var result = await _apisixHelpers.AddCorsToRoute(routeId);
    if (result)
    {
        return Ok("CORS added to route successfully");
    }
    return BadRequest("Failed to add CORS to route");
}

[HttpGet("routes")]
public async Task<IActionResult> GetAllRouteIds()
{
    var routeIds = await _apisixHelpers.GetAllRouteIds();
    return Ok(routeIds);
}

}


Nếu bạn muốn thực hiện một số logic liên quan đến APISIX cho mỗi request, bạn có thể tạo một middleware:

thì Đăng ký middleware này trong Program.cs: app.UseMiddleware<ApisixMiddleware>();

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

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.0.0 97 7/25/2024