I am trying to understand the frenzy of web API routing.
When I try to publish the data as follows:
curl -v -d "test" http:
I get 404 and the following error message:
{"Message":"No HTTP resource was found that matches the request URI 'http://localhost:8088/services/SendData'.","MessageDetail":"No action was found on the controller 'Test' that matches the request."}
Here is the code for my test server.
public class TestController : ApiController { [HttpPost] public void SendData(string data) { Console.WriteLine(data); } } class Program { static void Main(string[] args) { var config = new HttpSelfHostConfiguration("http://localhost:8088"); config.Routes.MapHttpRoute( name: "API Default", routeTemplate:"services/SendData", defaults: new { controller = "Test", action = "SendData"}, constraints: null); using (var server = new HttpSelfHostServer(config)) { server.OpenAsync().Wait(); Console.WriteLine("Press Enter to quit."); Console.ReadLine(); } } }
More generally, why the ASP.NET team decided to make the MapHttpRoute method so confusing. Why are two anonymous objects required ... how should someone know what properties these objects really need?
MSDN does not give any help: http://msdn.microsoft.com/en-us/library/hh835483(v=vs.108).aspx
All the pain of a dynamically typed language without any benefit if you ask me ...
source share