Aiursoft.AiurProtocol.Server 7.0.12

There is a newer version of this package available.
See the version list below for details.
dotnet add package Aiursoft.AiurProtocol.Server --version 7.0.12                
NuGet\Install-Package Aiursoft.AiurProtocol.Server -Version 7.0.12                
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="Aiursoft.AiurProtocol.Server" Version="7.0.12" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Aiursoft.AiurProtocol.Server --version 7.0.12                
#r "nuget: Aiursoft.AiurProtocol.Server, 7.0.12"                
#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 Aiursoft.AiurProtocol.Server as a Cake Addin
#addin nuget:?package=Aiursoft.AiurProtocol.Server&version=7.0.12

// Install Aiursoft.AiurProtocol.Server as a Cake Tool
#tool nuget:?package=Aiursoft.AiurProtocol.Server&version=7.0.12                

AiurProtocol

MIT licensed Pipeline stat Test Coverage NuGet version (Aiursoft.AiurProtocol.Abstractions) NuGet version (Aiursoft.AiurProtocol) NuGet version (Aiursoft.AiurProtocol.Server) ManHours

AiurProtocol defines an API programming practice to easily build a RESTful API. It simplifies the process of

  • Auto HTTP request path building
  • Strong-typed API model sharing
  • Auto HTTP status code translation
  • Auto error handling\error passthrough
  • Auto input model validation\local validation
  • Auto serialization and deserialization
  • Document generation

And the API it built is also standard Restful HTTP API, so you can call it with any programming language.

With AiurProtocol, you can focus on designing your API and forget about those complications!

Why this project?

API development is a challenging task that requires handling various aspects such as HTTP status codes, error handling, input validation, documentation writing, and log checking. However, this project aims to simplify the API development process by providing a unified best practice approach. By following this approach, developers can efficiently handle HTTP status codes, error handling, input validation, documentation writing, and log checking. This project's goal is to save time and effort, allowing developers to focus more on developing new features.

Installation

Run the following command to install Aiursoft.AiurProtocol.Server to your ASP.NET Core project from nuget.org:

dotnet add package Aiursoft.AiurProtocol.Server

Run the following command to install Aiursoft.AiurProtocol to your SDK project which sending requests to your server from nuget.org:

dotnet add package Aiursoft.AiurProtocol

dependency diagram

How to use on Server

Register AiurProtocol in your Startup.cs

// Your startup.cs on server
using Aiursoft.AiurProtocol.Server;

public void ConfigureServices(IServiceCollection services)
{
    services
        .AddControllers()
        .AddAiurProtocol(); // <---- Add this after add controllers!
}

Now you can go to your Controller and return the protocol!

// Your controller
using Aiursoft.AiurProtocol.Server;

public class HomeController : ControllerBase
{
    [Route("/api/hello-world")]
    public IActionResult Index()
    {
        return this.Protocol(Code.ResultShown, "Welcome to this API project!");
    }
}

How to use it to build an SDK

Now you need to write an SDK for your API.

After creating a new class library project, add the dependencies:


<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <TargetFramework>net7.0</TargetFramework>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>
    </PropertyGroup>
    <ItemGroup>
        <PackageReference Include="Aiursoft.AiurProtocol" Version="6.0.7" />
    </ItemGroup>
</Project>

Write the following method:

// In SDK
using Aiursoft.AiurProtocol;
using Microsoft.Extensions.DependencyInjection;

public class DemoServerConfig
{
    public string Instance { get; set; } = string.Empty;
}

public class DemoAccess
{
    private readonly AiurProtocolClient _http;
    private readonly DemoServerConfig _demoServerLocator;

    public DemoAccess(
        AiurProtocolClient http,
        IOptions<DemoServerConfig> demoServerLocator)
    {
        _http = http;
        _demoServerLocator = demoServerLocator.Value;
    }

    public async Task<AiurResponse> IndexAsync()
    {
        var url = new AiurApiEndpoint(host: _demoServerLocator.Instance, route: "/api/hello-world", param: new {});
        var result = await _http.Get<AiurResponse>(url);
        return result;
    }
}

public static IServiceCollection AddDemoService(this IServiceCollection services, string endPointUrl)
{
    services.AddAiurProtocolClient();
    services.Configure<DemoServerConfig>(options => options.Instance = endPointUrl);
    services.AddScoped<DemoAccess>();
    return services;
}

How to use your new SDK

Now you can write a new console app to use your new SDK to call your server!

// To get your SDK:
var services = new ServiceCollection();
services.AddDemoService(endpointUrl);
var serviceProvider = services.BuildServiceProvider();
var sdk = serviceProvider.GetRequiredService<DemoAccess>(); // Or from dependency injection

// To use your SDK:
var result = await sdk?.IndexAsync()!;

That's it! It will use your SDK to generate a new call to your server, and the result is right at your hand!

Advanced usage

Future features

It will support the following features in the future:

  • API rate limit
  • API version control
  • API documentation
  • API request logging and report

How to contribute

There are many ways to contribute to the project: logging bugs, submitting pull requests, reporting issues, and creating suggestions.

Even if you with push rights on the repository, you should create a personal fork and create feature branches there when you need them. This keeps the main repository clean and your workflow cruft out of sight.

We're also interested in your feedback on the future of this project. You can submit a suggestion or feature request through the issue tracker. To make this process more effective, we're asking that these include more information to help define them more clearly.

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Aiursoft.AiurProtocol.Server:

Package Downloads
Aiursoft.SDK

The base class, tools and extends for Aiursoft web apps.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on Aiursoft.AiurProtocol.Server:

Repository Stars
AiursoftWeb/Infrastructures
Mirror of: https://gitlab.aiursoft.cn/aiursoft/infrastructures
Version Downloads Last updated
8.0.23 88 11/18/2024
8.0.22 72 11/13/2024
8.0.21 92 10/28/2024
8.0.20 112 10/11/2024
8.0.19 87 10/10/2024
8.0.18 85 10/10/2024
8.0.17 80 10/9/2024
8.0.16 107 9/24/2024
8.0.15 85 9/24/2024
8.0.13 118 8/18/2024
8.0.12 69 7/10/2024
8.0.11 84 7/7/2024
8.0.10 101 6/29/2024
8.0.9 94 6/25/2024
8.0.8 95 6/13/2024
8.0.7 89 6/8/2024
8.0.6 76 6/5/2024
8.0.5 100 5/16/2024
8.0.4 106 5/4/2024
8.0.3 130 3/17/2024
8.0.2 105 2/25/2024
8.0.1 388 2/19/2024
8.0.0 125 2/19/2024
7.0.24 135 2/14/2024
7.0.23 117 2/4/2024
7.0.22 105 2/2/2024
7.0.21 107 2/2/2024
7.0.20 110 1/30/2024
7.0.19 125 1/18/2024
7.0.18 113 1/10/2024
7.0.17 138 1/4/2024
7.0.16 853 12/30/2023
7.0.15 130 12/24/2023
7.0.14 165 12/1/2023
7.0.13 284 11/26/2023
7.0.12 240 11/22/2023
7.0.11 229 11/21/2023
7.0.10 212 11/12/2023
7.0.7 197 11/2/2023
7.0.6 164 11/2/2023
7.0.5 219 10/31/2023
7.0.4 160 10/27/2023
7.0.3 310 10/11/2023
7.0.2 254 9/23/2023
7.0.1 224 9/13/2023
7.0.0 307 9/5/2023
6.0.11 181 8/20/2023
6.0.10 333 7/9/2023
6.0.9 240 7/9/2023
6.0.8 225 7/3/2023
6.0.7 226 6/26/2023
6.0.6 144 6/26/2023