Reputation: 5384
WebAPIConfig
config.Routes.MapHttpRoute(
name: "TestApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
My APIController:
public class TestController : ApiController
{
[HttpPost]
public string Send([FromBody] string id)
{
return "Got " + id;
}
}
this all works well until I CHANGE the NAME of the PARAM "ID" to let's say "input" on my API procedure.
MY (WRONG) ASSUMPTION
I was under the impression that by placing the {xx} brackets on the routing table url, we were really stating that any 1st param will be used from the requesting call.
This seems not true based on my little sample.
QUESTION 1:
Does this mean that if I have 10 API methods (that are like register, login, logout, sendemail ...) instead of the standard defaults get/post/put/delete ....i will need 10 separate Routing entries for each one?
QUESTION 2:
Also how do we represent on the routing table an API that expects a class of POCO fields?
Do we state each individual and separate field name on the MapHttpRoute?
Upvotes: 4
Views: 2490
Reputation: 16440
If you rename your action method's id
parameter to input
, every call to this action will have to pass a parameter named input
(not id
!) within the request body.
Since the parameter binding is based on matching names, you can't rename body parameters without updating the calling clients (if that's even possible). You can rename route parameter placeholders, though, when you update both the route definition and the corresponding action methods' parameters.
Upvotes: 2