UmbracoApiController - No HTTP resource was found that matches the request URI
I'm working on a custom API controller and when I have just a single action in there it resolves fine however adding a second it never resolves and I can't work out if it is a bug or I am missing something somewhere (with it being Monday morning and all!).
public class ScheduleApiController : UmbracoApiController
{
// GET: /Umbraco/Api/ScheduleApi/Get
public HttpResponseMessage Get()
{
... // This resolves just fine
}
// GET: /Umbraco/Api/ScheduleApi/GetByDay/2
public HttpResponseMessage GetByDay(int day)
{
... // This won't resolve
}
}
My second action simply returns the exception in the title of this post with the message detail of "No action was found on the controller 'ScheduleApi' that matches the request."
I think only a parameter called id can be auto passed by url so to get this route to work /Umbraco/Api/ScheduleApi/GetByDay/2 you would need your method to be like: public HttpResponseMessage GetByDay(int id)
Thanks Jeavon - looks like you are right on both counts there.
/Umbraco/Api/ScheduleApi/GetByDay/?day=2
This works, as does your second suggestion. Thanks for the pointers however it seems a bit odd don't you think that it's been implemented in this way? Whilst I would prefer to maintain a consistent structure for urls the method signature doesn't sit quite right with me referring to the day as the id.
Kinda, when you inherit from UmbracoApiController, your controller is auto routed so that you don't have to register your own route, however in native WebApi it is when you register a route that you can specify you own pattern. I don't know if this is possible with the UmbracoApi but I think it probably is....
Just to chime in, this is absolutely default ASP.NET Web Api behavior, we're not doing anything different from the defaults. We can't smell that you're going to use "day" instead of "id". Of course you can always define your own routes which expect a param called day like:
using System.Web.Http;
using System.Web.Routing;
using Umbraco.Core;
namespace My.Namespace
{
public class StartupEventHandlers : ApplicationEventHandler
{
public StartupEventHandlers()
{
UmbracoApplicationBase.ApplicationStarting += UmbracoApplicationStarting;
}
static void UmbracoApplicationStarting(object sender, System.EventArgs e)
{
RouteTable.Routes.MapHttpRoute("DefaultApi", "my/api/{controller}/{day}", new { day = RouteParameter.Optional });
}
}
}
So your GET would be: // GET: /My/Api/ScheduleApi/GetByDay/2
UmbracoApiController - No HTTP resource was found that matches the request URI
I'm working on a custom API controller and when I have just a single action in there it resolves fine however adding a second it never resolves and I can't work out if it is a bug or I am missing something somewhere (with it being Monday morning and all!).
My second action simply returns the exception in the title of this post with the message detail of "No action was found on the controller 'ScheduleApi' that matches the request."
Any ideas?
Thanks, Simon
Hi Simon,
Have you tried changing the first method to be called GetSomething(), I have a feeling that Get() does something special, but I might be wrong...
Jeavon
Wait, I remember, try /Umbraco/Api/ScheduleApi/GetByDay/?day=2
I think only a parameter called id can be auto passed by url so to get this route to work /Umbraco/Api/ScheduleApi/GetByDay/2 you would need your method to be like:
public HttpResponseMessage GetByDay(int id)
Thanks Jeavon - looks like you are right on both counts there.
This works, as does your second suggestion. Thanks for the pointers however it seems a bit odd don't you think that it's been implemented in this way? Whilst I would prefer to maintain a consistent structure for urls the method signature doesn't sit quite right with me referring to the day as the id.
Simon
Hi Simon,
Kinda, when you inherit from UmbracoApiController, your controller is auto routed so that you don't have to register your own route, however in native WebApi it is when you register a route that you can specify you own pattern. I don't know if this is possible with the UmbracoApi but I think it probably is....
Jeavon
Just to chime in, this is absolutely default ASP.NET Web Api behavior, we're not doing anything different from the defaults. We can't smell that you're going to use "day" instead of "id". Of course you can always define your own routes which expect a param called day like:
So your GET would be:
// GET: /My/Api/ScheduleApi/GetByDay/2
Hey Seb,
I thought I tried that yesterday but I think I had it in the wrong start up event or something as it works perfectly today!
If you don't want to have a whole new route you can add something to this:
Fairly useful actually :-)
Jeavon
is working on a reply...