yuapi-client-sdk
1.0.0
dotnet add package yuapi-client-sdk --version 1.0.0
NuGet\Install-Package yuapi-client-sdk -Version 1.0.0
<PackageReference Include="yuapi-client-sdk" Version="1.0.0" />
<PackageVersion Include="yuapi-client-sdk" Version="1.0.0" />
<PackageReference Include="yuapi-client-sdk" />
paket add yuapi-client-sdk --version 1.0.0
#r "nuget: yuapi-client-sdk, 1.0.0"
#:package yuapi-client-sdk@1.0.0
#addin nuget:?package=yuapi-client-sdk&version=1.0.0
#tool nuget:?package=yuapi-client-sdk&version=1.0.0
YuApiClient SDK
The YuApiClient SDK is a .NET library designed to facilitate API requests through a secure and managed pipeline. It integrates seamlessly with the Ocelot API Gateway, allowing for request logging, access control, user verification, quota checking, and response handling.
Features
- Request Logging: Automatically logs all requests for monitoring and debugging purposes.
- Access Control: Verifies interface information to ensure secure API access.
- User Verification: Authenticates users before processing their requests.
- Quota Checking: Manages and enforces invocation quotas for API endpoints.
- Response Handling: Processes and handles responses from API endpoints.
Installation
To install the YuApiClient SDK, use the NuGet Package Manager Console:
Install-Package YuApiClient
Or, you can add it to your project file:
<PackageReference Include="YuApiClient" Version="1.0.0" />
Usage
Initialization
First, initialize the YuApiClient with an HttpClient:
using YuApiClient;
var httpClient = new HttpClient { BaseAddress = new Uri("http://127.0.0.1:8090") };
var yuApiClient = new YuApiClient(httpClient);
Setting Access and Secret Keys
Set the access and secret keys for authentication:
yuApiClient.SetAccessKey("your-access-key");
yuApiClient.SetSecretKey("your-secret-key");
Invoking an API Method
You can invoke API methods using the InvokeAsync method:
try
{
var result = await yuApiClient.InvokeAsync("GetUsernameByPost", "{\"username\":\"exampleUser\"}");
Console.WriteLine(result);
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
Example: Fetching a Random Anime Image
To fetch a random anime image:
try
{
var imageBytes = await yuApiClient.InvokeAsync("GetRandomAnimeImage", string.Empty) as byte[];
if (imageBytes != null)
{
File.WriteAllBytes("random_anime_image.jpg", imageBytes);
Console.WriteLine("Image saved successfully.");
}
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
Methods
SetAccessKey(string accessKey)
Sets the access key for API authentication.
SetSecretKey(string secretKey)
Sets the secret key for API authentication.
InvokeAsync(string methodName, string serializedParams)
Invokes the specified API method with the given parameters. Returns the result as an object, which should be cast to the appropriate type.
GetRandomAnimeImage()
Fetches a random anime image as a byte array.
Middleware Pipeline
Requests made through the YuApiClient SDK are processed by the following middleware components:
- RequestLoggingMiddleware: Logs each request for audit and debugging purposes.
- AccessControlMiddleware: Ensures the request has proper access permissions.
- UserVerificationMiddleware: Authenticates the user making the request.
- QuotaCheckMiddleware: Ensures the user has not exceeded their request quota.
- ResponseHandlingMiddleware: Processes and formats the response before returning it to the client.
| 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. 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. |
-
net8.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.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0 | 222 | 7/13/2024 |
This package is designed to work with the YuAPI platform and requires proper configuration of the Ocelot API Gateway and related middleware for optimal performance.