首页 > 解决方案 > AspnetBoilerpate REST URL

问题描述

在浏览了文档和 github 问题之后,我找不到创建 RESTful api 的方法。如果我们想使用 RESTful,它仅指使用标准的 webapi 实现。

是否有另一种方法(无需完成重写当前的 webapi 实现)来获取 api 的 RESTful 并同时让服务代理与它们一起工作?

标签: angularasp.net-coreaspnetboilerplate

解决方案


您可以使用 Aspnet Boilerplate 创建 Restful API。这是一个示例,向您展示如何做到这一点。

public class TestAppService : SwagResterAppServiceBase, ITestAppService
{
    [Route("api/services/app/Test")]
    [HttpPost]
    public Task CreateTest(TestDetailsDto input)
    {
        throw new NotImplementedException();
    }

    [Route("api/services/app/Test")]
    [HttpDelete]
    public Task DeleteTest(EntityDto input)
    {
        throw new NotImplementedException();
    }

    [Route("api/services/app/Test")]
    [HttpGet]
    public Task GetTest(EntityDto input)
    {
        throw new NotImplementedException();
    }

    [Route("api/services/app/Test")]
    [HttpPut]
    public Task UpdateTest(TestDetailsDto input)
    {
        throw new NotImplementedException();
    }
}

public interface ITestAppService: IApplicationService, ITransientDependency
{

    Task CreateTest(TestDetailsDto input);


    Task DeleteTest(EntityDto input);


    Task GetTest(EntityDto input);


    Task UpdateTest(TestDetailsDto input);
}

public class TestDetailsDto
{

}

然后运行refresh.bat以重新生成服务代理。

大摇大摆的屏幕截图证明


推荐阅读