Search code examples
c#restasp.net-coreaspnetboilerplatehttp-method

How to use App Service methods as REST API endpoints?


POST /api/services/app/Company/Create is the URL we normally get when we create App Service in ASP.NET Boilerplate.

How can I achieve POST /api/services/app/Company using App Service? Because if I use OData, then some response format is not in ABP response format.

Here, POST is the HTTP method and Create is the name of the method in CompanyAppService of my ABP Application project. What I want is when I consume this API on any web app, then I should be able to call this API at /api/services/app/Company with HTTP method POST. I don't want to use Create, Update, Delete, Get, GetAll in URL that we are going to use while calling in web application.


Solution

  • You can achieve this by following way.

    [HttpPost("api/services/app/Company")]
    public async Task CreateCompany(CompanyDetailsDto input)
    
    [HttpDelete("api/services/app/Company")]
    public async Task DeleteCompany(EntityDto input)
    
    [HttpGet("api/services/app/Company")]
    public async Task GetCompany(EntityDto input)
    
    [HttpPut("api/services/app/Company")]
    public async Task UpdateCompany(CompanyDetailsDto input)