Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Nov 13, 2013 @ 17:00
    Ismail Mayat
    0

    WebApi routing

    I have the following web api controller:

        public class ProductApiController : UmbracoApiController
    {
        public IEnumerable<Product> GetAll(string homeId)
        {
            return ContentService.Instance.GetAllProducts(homeId);
        }
    }
    

    works fine you you call it like

    /Umbraco/Api/ProductApi/GetAll?homeId=1050
    

    however if you call it like

    /Umbraco/Api/ProductApi/GetAll/homeId/1050

    or

    /Umbraco/Api/ProductApi/GetAll/1050

    You get error

    "No HTTP resource was found that matches the request URI"

    So is this way of calling webapi which works as I have done it before outside of umbraco not work with umbraco webapi?

    Regards

    Ismail

  • Stefan Kip 1614 posts 4131 karma points c-trib
    Nov 13, 2013 @ 17:03
    Stefan Kip
    100

    Searching (http://our.umbraco.org/search?q=No%20HTTP%20resource%20was%20found%20that%20matches%20the%20request%20URI&content=forum,) gives the following topic with the same issue: http://our.umbraco.org/forum/developers/extending-umbraco/46086-UmbracoApiController-No-HTTP-resource-was-found-that-matches-the-request-URI

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Nov 13, 2013 @ 17:07
    Ismail Mayat
    0

    aha, makes sense that second post however at least you can map your own route then what ever you pass in will work.

    RouteTable.Routes.MapHttpRoute("ScheduleApi", "Umbraco/Api/ScheduleApi/{action}/{day}", new { controller = "ScheduleApi", day = RouteParameter.Optional });
    

    Cheers

    Ismail

  • Marc Goodson 2157 posts 14431 karma points MVP 9x c-trib
    Nov 13, 2013 @ 17:18
    Marc Goodson
    0

    If in your example you call it Id instead of homeId, it will work with the default root eg /umbraco/api/ProductApi/GetAll/1050

    publicIEnumerable<Product>GetAll(string Id)
  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Nov 13, 2013 @ 17:29
    Ismail Mayat
    2

    Marc,

    No that is a bit dirty in that id does not reflect intent of the parameter. I have got it working so i did

            public void OnApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            MapWebApiRoutes();
        }
    
        private void MapWebApiRoutes()
        {
            RouteTable.Routes.MapHttpRoute("ProductApi", "Umbraco/Api/ProductApi/{action}/{homeId}", 
                                                         new
                                                         {
                                                             controller = "ProductApi", homeId = RouteParameter.Optional
                                                         }
                                          );
        }
    

    and my url

    Umbraco/Api/ProductApi/GetAll/1050

    works.

    Regards

    Ismail

  • Marc Goodson 2157 posts 14431 karma points MVP 9x c-trib
    Nov 13, 2013 @ 17:41
    Marc Goodson
    0

    just illustrating why it wasn't working, ie homeid didn't match the current default route :-)

    but yes now you have a special custom route that 'knows about' the specialness of the  homeid parameter in your route.

     

  • antao 81 posts 371 karma points
    Dec 10, 2013 @ 22:36
    antao
    0

    Hey guys, just a question, can we have the route even more clean and "restfull"? Like this: 

    publicclass SomeApiController:UmbracoApiController
    {
       
    public IEnumerable<string> Get()
       
    {
           
    return new string[] {"our", "umbraco", "rocks" };
       
    }
    }

    And call it like this?

    /Umbraco/Api/SomeApi/

    Thanks! Joao.

Please Sign in or register to post replies

Write your reply to:

Draft