Api Method Name Attribute
Hi,
i just wonder what the name property inside the HttpMethod attribute is for? I read it can be used in MVC a lot when calling other controllers or getting their routes. So I have something like
Im usually used to something like
[HttpDelete("{id}")]
. I cannot specify both, right? I just create an api and want to be documentative/verbose about my code6 Replies
You can specify both
The name there is for the URL generator, for example. When you need a URL of this action, you can get it by the action name
You can also get it by the controller name and action method name, sure
But this tends to be easier
but that's only when I get the URL by the action in the code, right? it's not really changing the URL of my api?
thanks for the quick response 🙂
ye
Only things that influence the route are the
[Route]
and [Http<Method>]
attributesAlright, thanks! If i have a pure Api, I can leave it out then I guess
But just curious, to specify both i would do
[HttpDelete(Name = "DeleteLocation", RouteTemplate="{id}")]
?I think just
[HttpDelete("{id}", Name = "DeleteLocation")]
would work
Could be mistaken, though
If it doesn't, then yeah, what you sayalright, thanks