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 (3)

Showing the top 3 NuGet packages that depend on Biwen.QuickApi:

Package Downloads
Biwen.QuickApi.FeatureManagement

Package Description

Biwen.QuickApi.Storage.AliyunOss

Package Description

Biwen.QuickApi.MiniProfiler

Biwen.QuickApi ,NET9+ MinimalApi CQRS

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.0 32 11/13/2024
2.0.0-rc3 41 10/24/2024
2.0.0-rc2 48 9/26/2024
2.0.0-rc1 48 9/24/2024
1.6.3 90 8/29/2024
1.6.2 101 6/14/2024
1.6.1 104 5/22/2024
1.5.2.1 93 5/16/2024
1.5.2 110 5/15/2024
1.5.0 90 5/13/2024
1.4.3.2 94 5/10/2024
1.4.2.2 97 5/9/2024
1.4.2.1 107 4/10/2024
1.4.2 126 2/21/2024
1.4.1 221 12/8/2023
1.4.0 135 11/15/2023
1.3.8 129 11/9/2023
1.3.7.3 127 11/5/2023
1.3.7.2 142 11/2/2023
1.3.7.1 143 10/21/2023
1.3.7 137 10/19/2023
1.3.6 162 10/15/2023
1.3.5 135 10/12/2023
1.0.0 127 9/21/2023

MinimalAPI