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
<PackageReference Include="Sun.Core.ApisixClient" Version="1.0.0" />
paket add Sun.Core.ApisixClient --version 1.0.0
#r "nuget: Sun.Core.ApisixClient, 1.0.0"
// 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 | 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
- Microsoft.AspNetCore.Http.Abstractions (>= 2.2.0)
- Microsoft.Extensions.Configuration (>= 8.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 8.0.2)
- Microsoft.Extensions.DependencyInjection (>= 8.0.0)
- Microsoft.Extensions.Http (>= 8.0.0)
- Microsoft.Extensions.Options (>= 8.0.2)
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 |