Web Api doesn't have a default viewable page (aspx, html, etc) that can be viewed by navigating to the root (localhost:port
in this case). So that is the normal behavior. In order to access your Api through the controller you need to access it using the route template specified in your MapHttpRoute()
method.
So to access the GET
method in your Api you would open a browser and place localhost:port/api/{controllername}
into the url. {controllername}
would be set to the name of your controller class without Controller added to the end.
ex: If your controller looked like this:
public class TestController : ApiController {
public HttpResponseMessage Get() {
return something;
}
public HttpResponseMessage Get(int id) {
return something with id;
}
}
Then your url for the first Get()
would look like this:
localhost:port/api/test
And the url for the second Get(int id)
would look like this:
localhost:port/api/test/5