Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

AppService action routing using http attributes #7782


User avatar
0
maciek.przepiorka created

I'm trying to change API routing using HTTP attributes from Microsoft.AspNet.WebApi.Core NuGet package but can't get it working.

I've created the interface of service, implementation of this service and DTOs.

The DBAppServiceBase is the AppServiceBase for my ASP.NET Zero application. Code example below:

public class MyCustomAppService : DBAppServiceBase, IMyCustomAppService
    {
        [HttpGet]
        public TestDto TestAction(TestInput input)
        {
            return new UploadFileDto
            {
                Id = Guid.NewGuid(),
                Name = input.Name
            };
        }
    }

By default the TestAction is a HTTP POST. I want to change it to HTTP GET without changing its name. I've already tested adding Get prefix and it successfully changed the HTTP method to GET, but I don't want to add HTTP verb prefix to the action every time I want to change it from the HTTP POST.


3 Answer(s)
  • User Avatar
    1
    musa.demir created

    As the document says:

    You can use any ASP NET Core attributes to change the HTTP methods or routes of the actions. This requires you to add a reference to the Microsoft.AspNetCore.Mvc.Core package.

  • User Avatar
    0
    maciek.przepiorka created

    It worked, thanks.

    I've been using this document which says the same about adding Microsoft.AspNet.WebApi.Core: https://aspnetboilerplate.com/Pages/Documents/Dynamic-Web-API

  • User Avatar
    0
    musa.demir created

    Thank you. I will check it