ApiSix.CSharp.Sdk
3.3.1
.NET 5.0
This package targets .NET 5.0. The package is compatible with this framework or higher.
.NET Standard 2.0
This package targets .NET Standard 2.0. The package is compatible with this framework or higher.
.NET Framework 4.5
This package targets .NET Framework 4.5. The package is compatible with this framework or higher.
dotnet add package ApiSix.CSharp.Sdk --version 3.3.1
NuGet\Install-Package ApiSix.CSharp.Sdk -Version 3.3.1
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="ApiSix.CSharp.Sdk" Version="3.3.1"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ApiSix.CSharp.Sdk --version 3.3.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: ApiSix.CSharp.Sdk, 3.3.1"
#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 ApiSix.CSharp.Sdk as a Cake Addin #addin nuget:?package=ApiSix.CSharp.Sdk&version=3.3.1 // Install ApiSix.CSharp.Sdk as a Cake Tool #tool nuget:?package=ApiSix.CSharp.Sdk&version=3.3.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
c# SDK for Apache APISIX
More detailed documentation please refer to:
Apache APISIX 安装
Example
using ApiSix.CSharp.model;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Net;
namespace ApiSix.CSharp.Sdk.Test
{
public class AdminClientTest
{
private AdminClient adminClient;
[SetUp]
public void Setup()
{
Setting.Current.Endpoint = "192.168.3.128:9180";
Setting.Current.Version = "3.3.0";
Setting.Current.ApiKey = "edd1c9f034335f136f87ad84b625c8f1";
Setting.Current.Save();
adminClient = new AdminClient();
}
[Test]
public void Test1()
{
Assert.Pass();
}
[Test]
public void testUpstream()
{
var id = "2";
var upstream = new Upstream();
upstream.id = id;
upstream.name = "name" + id;
var nodes = new Dictionary<string, int>();
nodes.Add("127.0.0.1:8080", 1);
upstream.type = "roundrobin";
upstream.desc = "upstream created by c# sdk.";
upstream.nodes = nodes;
var up = adminClient.getUpstream("467815367964623559");
var ups = adminClient.listUpstreams();
try
{
adminClient.deleteUpstream(id);
}
catch (ApisixSDKExcetion e)
{
Assert.AreEqual(e.getErrorCode().ToString().ToString(), "404");
}
adminClient.putUpstream(id, upstream);
//adminClient.postUpstream(upstream);
upstream.desc = "upstream created by c# sdk.2";
try
{
adminClient.putUpstream(id, upstream);
//adminClient.postUpstream(upstream);
}
catch (ApisixSDKExcetion e)
{
Assert.AreEqual(e.getErrorCode().ToString(), "400");
}
up = adminClient.getUpstream(id);
Assert.That(up.value.desc, Is.EqualTo(upstream.desc));
Assert.That(up.value.type, Is.EqualTo("roundrobin"));
var list = adminClient.listUpstreams();
int size1 = list.total;
//must has 1 or more routes
Assert.True(size1 > 0);
//delete not exist route
try
{
adminClient.deleteUpstream("id-not-exists");
}
catch (ApisixSDKExcetion e)
{
Assert.AreEqual(e.getErrorCode().ToString(), "404");
}
Assert.True(adminClient.deleteUpstream(id));
try
{
adminClient.getUpstream(id);
}
catch (ApisixSDKExcetion e)
{
Assert.AreEqual(e.getErrorCode().ToString(), "404");
}
}
[Test]
public void testService()
{
var id = "2";
Service service = new Service();
service.name = "servicename" + id;
Upstream upstream = new Upstream();
upstream.id = id;
upstream.name = "name" + id;
Dictionary<String, int> nodes = new Dictionary<String, int>();
List<String> methods = new List<String>();
nodes.Add("127.0.0.1:8080", 1);
methods.Add("GET");
upstream.type = ("roundrobin");
upstream.nodes = (nodes);
LimitCount lmt = new LimitCount();
lmt.count = (2);
lmt.key = ("remote_addr");
lmt.rejectedCode = (503);
lmt.timeWindow = (60);
var plugins = new Dictionary<string, Plugin>();
plugins.Add("limit-count", lmt);
service.upstream = (upstream);
service.desc = ("service created by c# sdk.s");
service.plugins = (plugins);
var svcs = adminClient.listServices();
adminClient.putService(id, service);
var svc = adminClient.getService(id);
Assert.AreEqual(service.desc, svc.value.desc);
var list = adminClient.listServices();
int size1 = list.total;
//must has 1 or more services
Assert.True(size1 > 0);
//delete not exist service
try
{
adminClient.deleteService("id-not-exists");
}
catch (ApisixSDKExcetion e)
{
Assert.AreEqual(e.getErrorCode().ToString(), "404");
}
var delRes = adminClient.deleteService(id);
Assert.True(delRes);
try
{
svc = adminClient.getService(id);
}
catch (ApisixSDKExcetion e)
{
Assert.AreEqual(e.getErrorCode().ToString(), "404");
}
}
[Test]
public void testRoute()
{
var list1 = adminClient.listRoutes();
//创建upstream
var upstreamId = "3";
Upstream upstream = new Upstream();
Dictionary<String, int> nodes = new Dictionary<String, int>();
nodes.Add("127.0.0.1:8080", 1);
nodes.Add("127.0.0.1:8180", 1);
upstream.name = "upstreamname" + upstreamId;
upstream.type = ("roundrobin");
upstream.desc = ("upstream created by c# sdk.");
upstream.nodes = (nodes);
adminClient.putUpstream(upstreamId, upstream);
//创建service
String serviceId = "3";
Service service = new Service();
LimitCount lmt = new LimitCount();
lmt.count = (2);
lmt.key = ("remote_addr");
lmt.rejectedCode = (503);
lmt.timeWindow = (60);
var plugins = new Dictionary<string, Plugin>();
plugins.Add("limit-count", lmt);
service.name= "servicename" + serviceId;
service.upstreamId = (upstreamId);
service.desc = ("service created by c# sdk.");
service.plugins = (plugins);
adminClient.putService(serviceId, service);
var routeId = "3";
Route route = new Route();
List<String> methods = new List<String>();
methods.Add("GET");
upstream.type = ("roundrobin");
upstream.nodes = (nodes);
route.uri = ("/helloworld");
route.desc = ("route created by c# sdk");
route.methods = (methods);
route.ServiceId = (serviceId);
route.name = routeId;
route.status = 1;
route.labels = new Dictionary<string, string>();
route.labels["test"] = "test";
route.labels["API_VERSION"] = "v2";
adminClient.putRoute(routeId, route);
var routeEntity = adminClient.getRoute(routeId);
Assert.AreEqual("/helloworld", routeEntity.value.uri);
Assert.AreEqual(serviceId, routeEntity.value.ServiceId);
var list = adminClient.listRoutes();
int size1 = list.total;
//must has 1 or more routes
Assert.True(size1 > 0);
//delete not exist route
try
{
adminClient.deleteRoute("id-not-exists");
}
catch (ApisixSDKExcetion e)
{
Assert.AreEqual(e.getErrorCode().ToString(), "404");
}
Assert.True(adminClient.deleteRoute(routeId));
Assert.True(adminClient.deleteService(serviceId));
Assert.True(adminClient.deleteUpstream(upstreamId));
list = adminClient.listRoutes();
int size2 = list.total;
//size minus
Assert.AreEqual(size1, size2 + 1);
try
{
adminClient.getRoute(routeId);
}
catch (ApisixSDKExcetion e)
{
Assert.AreEqual(e.getErrorCode().ToString(), "404");
}
}
[Test]
public void testK8sInfo()
{
//创建upstream
Upstream upstream = new Upstream();
Dictionary<String, int> nodes = new Dictionary<String, int>();
K8sDeploymentInfo k8sInfo = new K8sDeploymentInfo();
k8sInfo.Namespace = ("test-namespace");
k8sInfo.deployName = ("test-deploy");
k8sInfo.serviceName = ("test-service");
k8sInfo.port = (8080);
k8sInfo.backendType = ("pod");
String routeId = "3";
Route route = new Route();
List<String> methods = new List<String>();
nodes.Add("127.0.0.1:8080", 1);
methods.Add("GET");
upstream.type = ("roundrobin");
upstream.nodes = (nodes);
upstream.k8sDeploymentInfo = (k8sInfo);
route.uri = ("/helloworld");
route.desc = ("route created by c# sdk");
route.methods = (methods);
route.upstream = (upstream);
adminClient.putRoute(routeId, route);
var routeEntity = adminClient.getRoute(routeId);
Assert.AreEqual("/helloworld", routeEntity.value.uri);
var list = adminClient.listRoutes();
int size1 = list.total;
//must has 1 or more routes
Assert.True(size1 > 0);
//delete not exist route
try
{
adminClient.deleteRoute("id-not-exists");
}
catch (ApisixSDKExcetion e)
{
Assert.AreEqual(e.getErrorCode().ToString(), "404");
}
var Namespace = k8sInfo.Namespace;
String deployName = k8sInfo.deployName;
String serviceName = k8sInfo.serviceName;
String upstreamId = Namespace + "-" + deployName + "-" + serviceName;
try
{
Assert.True(adminClient.deleteRoute(routeId));
Assert.True(adminClient.deleteUpstream(upstreamId));
}
catch (ApisixSDKExcetion e)
{
Assert.AreEqual(e.getErrorCode().ToString(), "404");
}
list = adminClient.listRoutes();
int size2 = list.total;
//size minus
Assert.AreEqual(size1, size2 + 1);
try
{
adminClient.getRoute(routeId);
}
catch (ApisixSDKExcetion e)
{
Assert.AreEqual(e.getErrorCode().ToString(), "404");
}
}
[Test]
public void testConsumer()
{
var csms = adminClient.listConsumers();
var username = "test";
Consumer consumer = new Consumer();
var keyAuth = new KeyAuth();
keyAuth.key = ("testkey");
var plugins = new Dictionary<string, Plugin>();
plugins.Add("key-auth", keyAuth);
consumer.username = ("test");
consumer.desc = ("consumer created by c# sdk.");
consumer.plugins = (plugins);
adminClient.putConsumer(username, consumer);
var csm = adminClient.getConsumer(username);
Assert.AreEqual("consumer created by c# sdk.", csm.value.desc);
Assert.AreEqual(username, csm.value.username);
//delete not exist consumer
try
{
adminClient.deleteConsumer("id-not-exists");
}
catch (ApisixSDKExcetion e)
{
Assert.AreEqual(e.getErrorCode().ToString(), "404");
}
Assert.True(adminClient.deleteConsumer(username));
try
{
adminClient.getConsumer(username);
}
catch (ApisixSDKExcetion e)
{
Assert.AreEqual(e.getErrorCode().ToString(), "404");
}
}
[Test]
public void testSSL()
{
String id = "2";
SSL ssl = new SSL();
ssl.cert = ("fake-cert-contentfake-cert-contentfake-cert-contentfake-cert-contentfake-cert-contentfake-cert-contentfake-cert-contentfake-cert-contentfake-cert-contentfake-cert-contentfake-cert-contentfake-cert-content");
ssl.key = ("fake-key-contentfake-key-contentfake-key-contentfake-key-contentfake-key-contentfake-key-contentfake-key-contentfake-key-contentfake-key-contentfake-key-contentfake-key-contentfake-key-contentfake-key-content");
ssl.snis = new List<string> { "sni.cn" };
adminClient.putSSL(id, ssl);
var s = adminClient.getSSL(id);
//Assert.AreEqual("sni.cn", s.value.sni);
//delete not exist ssl
try
{
adminClient.deleteSSL("id-not-exists");
}
catch (ApisixSDKExcetion e)
{
Assert.AreEqual(e.getErrorCode(),404);
}
Assert.True(adminClient.deleteSSL(id));
try
{
adminClient.getSSL(id);
}
catch (ApisixSDKExcetion e)
{
Assert.AreEqual(e.getErrorCode().ToString(), "404");
}
}
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 is compatible. 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
.NET Framework | net45 is compatible. net451 was computed. net452 was computed. net46 was computed. net461 was computed. net462 is compatible. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. 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.
-
.NETFramework 4.5
- Newtonsoft.Json (>= 13.0.3)
-
.NETFramework 4.6.2
- Newtonsoft.Json (>= 13.0.3)
-
.NETStandard 2.0
- Newtonsoft.Json (>= 13.0.3)
-
.NETStandard 2.1
- Newtonsoft.Json (>= 13.0.3)
-
net5.0
- Newtonsoft.Json (>= 13.0.3)
-
net6.0
- Newtonsoft.Json (>= 13.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.