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
                    
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="yuapi-client-sdk" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="yuapi-client-sdk" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="yuapi-client-sdk" />
                    
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 yuapi-client-sdk --version 1.0.0
                    
#r "nuget: yuapi-client-sdk, 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.
#:package yuapi-client-sdk@1.0.0
                    
#: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=yuapi-client-sdk&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=yuapi-client-sdk&version=1.0.0
                    
Install as a Cake Tool

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:

  1. RequestLoggingMiddleware: Logs each request for audit and debugging purposes.
  2. AccessControlMiddleware: Ensures the request has proper access permissions.
  3. UserVerificationMiddleware: Authenticates the user making the request.
  4. QuotaCheckMiddleware: Ensures the user has not exceeded their request quota.
  5. ResponseHandlingMiddleware: Processes and formats the response before returning it to the client.
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.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.