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)
-
1
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.
-
0
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 -
0
Thank you. I will check it