I have a basic asp.net self host app that makes use of the HttpConfiguration class and includes this route:
config.Routes.MapHttpRoute(
name: "login",
routeTemplate: "login",
defaults: new { controller = "Login", action = "Get" }
);
i would like to define actions based on HTTP verbs included in the request instead of specified in the URL.
i.e.
curl http://domain/login -X GET
Should call the Get
method on the LoginController
class. And
curl http://domain/login -X POST -H 'Content-Length: 1' -d 'x'
Should call the Post 'Post' method in the controller class. I have been able to test that the post request works if I adjust the route configuration to
config.Routes.MapHttpRoute(
name: "login",
routeTemplate: "login/{action}",
defaults: new { controller = "Login", action = "Get" }
);
and then curl
to:
curl http://domain/login/post -X POST -H 'Content-Length: 1' -d 'x'
But this is specifying the post verb in the http request and URI (which I would prefer not to do).
===== EDIT
The answer by levi here: https://stackoverflow.com/a/2143991/3114742 solved my problem