Copied to clipboard

Flag this post as spam?

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


  • Frederik Østerbye 11 posts 81 karma points
    Jan 30, 2014 @ 15:12
    Frederik Østerbye
    0

    Routing to ApiController in 7.0.2

    I'm building an extension to the back-end.

    I want my edit-views to retrieve data from an ApiController so I followed the tutorial here.

    I get a 404-error, when I try to get the data from the Api controller.

    It seems that there has been som changes to the routing paths in the 7.0.2 (read article here)

    The article states: "It is good practice to never hard code any URLs based on both WebAPI or MVC controllers because routes can change. The UrlHelper for both WebAPI and MVC should be used instead to generate the URL for a particular route."

    Well, the tutorial hard codes the URL's which is where I'm stuck. I've tried the fix mentioned in the article but to no avail. The article also mentions a "UrlHelper", which seems could be handy for this kinda problem; I can't find any documentation on how to use this, though.

    Also: Where is the URL to the Api Controller documentet? I kinda pattern-matched the URL from the tutorial to my own application but I'm not really sure it's right.

    Application-Name: "Races", Controller-name: "PersonApiController", Method: "GetById"

    Url: "/Backoffice/Races/DistanceApi/GetById?id=[id]" - where [id] is some id route path.

    Best regards

    Frederik

  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Jan 30, 2014 @ 16:13
    Ismail Mayat
    0

    Frederik,

    Try and get your url like

    string apiUrl = Url.GetUmbracoApiService

    Also in OnApplicationStarting are you wiring up routes?

                RouteTable.Routes.MapHttpRoute("ProductApi", "Umbraco/Api/ProductApi/{action}/{homeId}/{answers}", 
                                                         new
                                                         {
                                                             controller = "ProductApi", 
                                                             homeId = RouteParameter.Optional,
                                                             answers = RouteParameter.Optional
                                                         }
                                          );
    
            //routes for new site language creator
            RouteTable.Routes.MapHttpRoute("NewSiteLanguageApi", "Umbraco/Api/NewSiteLanguageApi/{action}/{languageCode}",
                                             new
                                             {
                                                 controller = "NewSiteLanguageApi",
                                                 languageCode = RouteParameter.Optional
                                             }
                              );
    
            //routes for eloqua api
            RouteTable.Routes.MapHttpRoute("EloquaApi", "Umbraco/Api/EloquaApi/{action}/{emailAddress}",
                                             new
                                             {
                                                 controller = "EloquaApi",
                                                 emailAddress = RouteParameter.Optional
                                             }
                              );
    
  • Frederik Østerbye 11 posts 81 karma points
    Jan 30, 2014 @ 18:18
    Frederik Østerbye
    0

    Hi Ismail

     

    Thanks for the response :-)

     

    The URL:

    I think we are talking about different things (I admit that I was a little vague in my initial description)

    I'm talking about reaching the ApiController from the resource.js-file (which in terms supplement the angular-controller with data).

    I must admit that I'm fairly new to the angular-framework so please bear with me if I have misunderstood some concept.

     

    The route wiring:

    I was under the impression that the attribute "[PluginController("Races")]" did the wiring for me, since this wasn't described in the tutorial.

     

    Thanks in advance

    Frederik

  • Kev Sherratt 2 posts 22 karma points
    Jan 31, 2014 @ 11:49
    Kev Sherratt
    0

    Hi. I've previously had a v7.0 api controller working but have been concentrating on the front-end since upgrading to 7.02; today I revisited to find it had stopped working and found your comment here about the breaking change. I guess I should actually read release notes once in a while! :)

    I too was suffering from a 404 on the backoffice API controller and I found that the details in the "breaking change" page you link to provides incorrect information. In my solution at least, instead of

    /umbraco/backoffice/{controller}/{action}
    

    it should be

    /umbraco/backoffice/api/{controller}/{action}
    

    I've also posted a comment on the referenced page.

    I hope this helps.

  • Frederik Østerbye 11 posts 81 karma points
    Jan 31, 2014 @ 12:51
    Frederik Østerbye
    0

    Hi Kevin

    Thank you for your response.

    I have tried the following:

    With area-name:

    /umbraco/backoffice/api/Races/DistanceApi/GetById

    Without area-name:

    /umbraco/backoffice/api/DistanceApi/GetById

    But it still doesn't seem to work. Any ideas?

    - Frederik

Please Sign in or register to post replies

Write your reply to:

Draft