The Web API framework maps incoming requests to the appropriate action based upon the HTTP verb of the request.
The Web API route URLs to a controller, and then to the action which matches the HTTP verb of the request message. Action methods on the controller must either match the HTTP action verb, or at least include the action verb as a prefix for the method name.
The default route template for a Web API Project is {controller}/{id} where the {id} parameter is optional.
For example -
i). http://apidomain/values i.e.
GET api/values - it included as a part of an HTTP GET message that map to Get() mehtod
ii). http://apidomain/values/5 i.e.
// GET api/values/5 - it included as a part of an HTTP GET messag that map to Get(id) method
Web API route templates may optionally include an {action} parameter. However, the action methods defined on the controller must be named with the proper HTTP action verb as a prefix in order for the routing to work.
In matching incoming HTTP messages to controllers, the Web API framework identifies the proper controller by appending the literal "Controller" to the value of the {controller} route parameter, then scans the project for a class matching that name.
Actions are selected from the controller by considering the non-complex route parameters, and matching them by name to the arguments of each method which matches the HTTP verb of the request.
URLs in Web API cannot contain complex types. Complex types must be placed in the HTTP message body.
0 Comment(s)