Biwen.QuickApi 1.0.0

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

// Install Biwen.QuickApi as a Cake Tool
#tool nuget:?package=Biwen.QuickApi&version=1.0.0

Biwen.QuickApi

项目介绍

- 提供一种简单集成的Minimal Web Api交互模块
- 开箱即用的 路由 和 权限 以及 Request验证体验
- 该库是NET WebApi/Minimal Api的补充,性能≈MinimalApi,遥遥领先于MVC和WebApi,但是提供了最简单的的使用体验
- write less, do more ; write anywhere, do anything

使用方式

Step1 UseBiwenQuickApis


builder.Services.AddBiwenQuickApis();
//....
app.MapBiwenQuickApis();


Step2 Define Request and Response


    public class HelloApiRequest : BaseRequest<HelloApiRequest>
    {
        public string? Name { get; set; }

        public HelloApiRequest()
        {
            RuleFor(x => x.Name).NotNull().Length(5, 10);
        }
    }

    public class HelloApiResponse : BaseResponse
    {
        public string? Message { get; set; }
    }


Step3 Define QuickApi


    /// <summary>
    /// get ~/admin/index
    /// </summary>
    [QuickApi("index", Group = "admin", Verbs = Verb.GET | Verb.POST, Policy = "admin")]
    public class NeedAuthApi : BaseQuickApi
    {
        public override EmptyResponse Execute(EmptyRequest request)
        {
            return EmptyResponse.Instance;
        }
    }

    /// <summary>
    /// get ~/hello/world/{name}
    /// </summary>
    [QuickApi("world/{name}", Group = "hello", Verbs = Verb.GET | Verb.POST)]
    public class HelloApi : BaseQuickApi<HelloApiRequest, HelloApiResponse>
    {
        private readonly HelloService _service;
        private readonly IHttpContextAccessor _httpContextAccessor;

        public Hello4Api(HelloService service,IHttpContextAccessor httpContextAccessor)
        {
            _service = service;
            _httpContextAccessor = httpContextAccessor;
        }

        public override HelloApiResponse Execute([From(RequestFrom.FromRoute)HelloApiRequest request)
        {
            var hello = _service.Hello($"hello world {_httpContextAccessor.HttpContext!.Request.Path} !");
            return new HelloApiResponse
            {
                Message = hello
            };
        }
    }

Step4 Enjoy !


//通过服务调用QuickApi
app.MapGet("/fromapi", (Biwen.QuickApi.DemoWeb.Apis.Hello4Api api) =>
{
    //通过你的方式获取请求对象
    var req = new EmptyRequest();
    //验证请求对象
    var validator = req.RealValidator as IValidator<EmptyRequest>;
    if (validator != null)
    {
        var result = validator.Validate(req);
        if (!result.IsValid)
        {
            return Results.BadRequest(result.ToDictionary());
        }
    }
    //执行请求
    var x = api.Execute(new EmptyRequest());
    return Results.Ok(x);
});

//直接访问
// GET ~/hello/world/biwen
// GET ~/hello/world/biwen?name=biwen
// POST ~/hello/world/biwen


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 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. 
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.6.1 71 5/22/2024
1.5.2.1 71 5/16/2024
1.5.2 86 5/15/2024
1.5.0 65 5/13/2024
1.4.3.2 73 5/10/2024
1.4.2.2 72 5/9/2024
1.4.2.1 81 4/10/2024
1.4.2 104 2/21/2024
1.4.1 195 12/8/2023
1.4.0 111 11/15/2023
1.3.8 100 11/9/2023
1.3.7.3 102 11/5/2023
1.3.7.2 109 11/2/2023
1.3.7.1 111 10/21/2023
1.3.7 114 10/19/2023
1.3.6 131 10/15/2023
1.3.5 110 10/12/2023
1.0.0 102 9/21/2023

MinimalAPI