# Cike.AutoApi **Repository Path**: fengwuyan/auto-web-api ## Basic Information - **Project Name**: Cike.AutoApi - **Description**: 🔥无需创建Controller,根据restful规范 将业务层 动态生成控制器🔥 - **Primary Language**: C# - **License**: MIT - **Default Branch**: develop - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 3 - **Forks**: 2 - **Created**: 2023-01-10 - **Last Updated**: 2024-05-20 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Cike.AutoApi #### Description 🔥Automatic api to make your code more concise 🔥. If your controller layer simply relays code from the business layer, like the following, then the automated api is a great fit for your project. The automated api dynamically generates controllers directly based on your business-layer methods, combined with restful specifications. > The controller just forwards and doesn't do anything, creating a lot of redundant code ```c# public class UserController:ControllerBase { private readonly IUserAppService _userAppService; public UserController(IUserAppService userAppService) { _userAppService=userAppService; } [HttpGet] public async Task>> GetListAsync(xxxDto input) { return await _userAppService.GetListAsync(input); } [HttpPost] public async Task CreateAsync(xxxDto input) { return await _userAppService.CreateAsync(input); } [HttpPost] public async Task UpdateAsync(Guid id,xxxDto input) { return await _userAppService.UpdateAsync(id,input); } } ``` #### Software Architecture * This project relies on.net6 #### Installation ```shell dotnet add package Cike.AutoApi ``` #### Instructions 1. Add the following two pieces of code in ```Program.cs``` ```c# //The 'AddAutoApiService' method must be placed after the 'AddControllers' or 'AddMvc' method. builder.Services.AddAutoApiService(opt => { //Add dynamic api configuration to the assembly where NETServiceTest resides opt.CreateConventional(typeof(NETServiceTest).Assembly); }); ``` 2. Business layer code, just need to inherit ```IAutoApiService``` interface ```c# public class TestService : IAutoApiService { public async Task> CreateAsync(TestCreateUpdateInput input) { return new List { $"{input.Code}|{input.Name}" }; } public async Task GetListAsync(string keyword) { return keyword; } public async Task> UpdateAsync(Guid id, TestCreateUpdateInput input) { return new List { $"{id}|{input.Code}|{input.Name}" }; } /// /// Upload file. If you upload files,Please use IAutoApiStreamContent[] . /// /// /// public async Task ImportAsync(IAutoApiStreamContent file) { using var fileStream = file.GetStream(); return file.FileName; } } ``` 3. Final effect ![Final effect](./doc/%E8%BF%90%E8%A1%8C%E6%95%88%E6%9E%9C%E5%9B%BEen.png)