Copied to clipboard

Flag this post as spam?

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


  • Michael Hyldsgaard 64 posts 124 karma points
    Mar 08, 2013 @ 14:52
    Michael Hyldsgaard
    1

    Web API - routing not working

    Umbraco v6.1

    I've created the following controller, but when accessing http://domain/Umbraco/Api/GetAllProducts I just get a 404.

    Any idea what I'm doing wrong?

    using System.Collections.Generic; using Umbraco.Web.WebApi;

    namespace UmbracoWebAPI.Controllers {     public class ProductsApiController : UmbracoApiController { public IEnumerable<string> GetAllProducts() { return new[] { "Table", "Chair", "Desk", "Computer", "Beer fridge" }; } } }

  • Kasper Holm 47 posts 180 karma points
    Mar 08, 2013 @ 14:56
    Kasper Holm
    0

    hello Michael
    hmm i think your missing the controller name :)
    like /Umbraco/Api/[YourControllerName]/[Method]

  • Michael Hyldsgaard 64 posts 124 karma points
    Mar 08, 2013 @ 14:58
    Michael Hyldsgaard
    0

    Hi Kasper.

    I think I've tried all possible combinations... can't get anything else than an 404 error... :o/

  • Kasper Holm 47 posts 180 karma points
    Mar 08, 2013 @ 15:17
    Kasper Holm
    0

    hello Agien :)
    have you tried to see what the URL is ? :)

    @Url.GetUmbracoApiService<ProductsApiController>("GetAllProducts")
  • Nick 11 posts 36 karma points
    Apr 24, 2013 @ 14:01
    Nick
    5

    Hello,

    I had the same problem, turns out you need to include the "Api" part of your controller. 

    So the Url would be ~/Umbraco/Api/ProductsApi/GetAllProducts

    Also it seems you can't use the RESTful setup because it doesn't support the Get/Get(id) methods at the same time.

  • Philip 59 posts 73 karma points
    Jul 25, 2013 @ 14:39
    Philip
    0

    Since you are in the Product-context, it isn't purely REST (Can be a hot topic ;) ) to do GetAllProducts. Just change it to Get(). Otherwise you would have to do some custom routing (unless Umbraco does something special for you here...).

     Never mind, it seems like Umbraco has setup some routing to do this...

Please Sign in or register to post replies

Write your reply to:

Draft