I am learning how ASP.NET Core Web API works, and I am a bit confused on how request's are routed within a controller.
I understand that the URI is typically /controllername-"controller"/action
. So something like UsersController
would be /api/Users/
.
However I have seen some variations in code at work, that either don't include a Route
attribute, and the attribute doesn't include a placeholder identifier.
For example a method called Get(int id)
within a UsersController
is said to be users<id>
but how does .Net know this?
Furthermore for something that isn't an obvious Get
or Put
, but an actual method name like GetWidgetInfo(int widgetId)
. I'm assuming .NET Core is able to just figure out this takes a URI resource parameter appended after the function name? IE: api/users/getwidgetinfo/<id>
. What are the rules for this?
(New .NET Core seems to always have placeholder values on the attribute, but I'm still not sure how it handles naming/routes with methods)