Coder Social home page Coder Social logo

apilite's Introduction

ApiLite

ApiLite是直接将Service层自动生成api路由,可以不用添加Controller,支持模块插件化,在项目开发中能够提高工作效率,降低代码量。

开发环境

  • .NET SDK 6.0.100-rc.2.21505.57
  • VS2022 Preview 7.0

示例目标

  • 根据Service动态生成api
  • 支持自定义路由模板(通过Route特性定义)
  • 支持模块插件化
  • 支持不同模块,相同Service名称的路由(命名空间需要有3级以上,例如:Com.Mod.XXX)
  • 自动根据方法名称判断请求方式,Get开头的方法名为GET请求,其他为POST请求

编码约定

  • 模块类库必须包含继承IModule接口的类
  • 需要生成api的Service必须继承IService接口
  • GET请求的方法必须以Get开头

使用示例

KHost.Run(args, o =>
{
    o.Modules.Add(new TestModule());//添加模块
});

class TestModule : IModule
{
    public void Initialize()
    {
    }
}

public class TestService : IService
{
    public string GetName(string name)
    {
        return $"Hello {name}";
    }

    public string SaveData(string data)
    {
        return $"{DateTime.Now:yyyy-MM-dd HH:mm:ss} {data}";
    }

    [Route("api/test")]
    public string GetCustMethod(string id)
    {
        return id;
    }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.