Base solution for your next web application
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.

Markdown is supported
Copy & paste or drag & drop images (max 30 MB per image)

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.

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • 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

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    musa.demir created

    Thank you. I will check it

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)