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.
<PackageVersion Include="Biwen.QuickApi" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Biwen.QuickApi" />
                    
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 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.
#:package Biwen.QuickApi@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=Biwen.QuickApi&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Biwen.QuickApi&version=1.0.0
                    
Install as a Cake Tool

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.  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 (4)

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

Package Downloads
Biwen.QuickApi.FeatureManagement

Package Description

Biwen.QuickApi.Contents

Package Description

Biwen.QuickApi.MiniProfiler

Biwen.QuickApi ,NET9+ MinimalApi CQRS

Biwen.QuickApi.Storage.AliyunOss

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.5 330 5/14/2025
2.0.3 257 3/31/2025
2.0.2 189 2/18/2025
2.0.1 167 1/16/2025
2.0.0 241 11/13/2024
2.0.0-rc3 101 10/24/2024
2.0.0-rc2 113 9/26/2024
2.0.0-rc1 93 9/24/2024
1.6.3 180 8/29/2024
1.6.2 196 6/14/2024
1.6.1 204 5/22/2024
1.5.2.1 187 5/16/2024
1.5.2 179 5/15/2024
1.5.0 170 5/13/2024
1.4.3.2 191 5/10/2024
1.4.2.2 206 5/9/2024
1.4.2.1 202 4/10/2024
1.4.2 198 2/21/2024
1.4.1 315 12/8/2023
1.4.0 209 11/15/2023
1.3.8 181 11/9/2023
1.3.7.3 203 11/5/2023
1.3.7.2 196 11/2/2023
1.3.7.1 192 10/21/2023
1.3.7 199 10/19/2023
1.3.6 222 10/15/2023
1.3.5 222 10/12/2023
1.0.0 192 9/21/2023

MinimalAPI