I would like to read about MVC4 WEB API's naming conventions, but I can't find any documentation about it. I would like to know if I can create endpoints with custom names and if so, how can I do that?
Use plural form in naming resources in your path to avoid a mesh of singular and plural path variants for the same resource, which complicates the API implementation. Don't use verbs in naming your path resources, use plural nouns.
A RESTful web service request contains: An Endpoint URL. An application implementing a RESTful API will define one or more URL endpoints with a domain, port, path, and/or query string — for example, https://mydomain/user/123?format=json .
The convention in MVC4 Web API is that the url starts with /api/ then has your controller name. From there, you don't specify the action name like you would normally do. The Controller Action is determined by the type of the request (GET, PUT, POST, DELETE). So you can create any end point that you want by creating a controller that inherits from API Controller.
The convention is; - Controller as your controller class name. - /api/ as the uri.
Let's say you want a tasks controller. Create a controller TasksController with a method Get(), then the uri would be /api/tasks.
The same goes for PUT, DELETE, and POST.
So again to answer your question... "I would like to know if i can create endpoints with custom names and if so, how can i do that?"
You can. Just create a controller that inherits from ApiController. You can name it whatever you want as log as it ends with Controller. ie ( MyController, TasksController, etc)
If you want to understand how you can configure routes to your controllers actions (I believe this is what you mean by endpoints in this context), than you should read Routing in ASP.NET Web API article.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With