Quantcast
Channel: Developer to developer
Viewing all articles
Browse latest Browse all 9076

Route /api/episerver/v2.0/content not found (but /api/episerver/v2.0/site is)

$
0
0

Hello,

I'm trying to enable the Content Delivery Api in my application, but it seems I have a problem with routing. I simply added the NuGet packages "EPiServer.ContentDeliveryApi.Cms" and "EPiServer.ContentDeliveryApi.Core" to my project. I then tested this configuration by making a call from a browser (authenticated) from JavaScript. The call looks like follows:

// jQuery
$.ajax({
   url: "/api/episerver/v2.0/content",
   type: "GET",
   beforeSend: function(xhr){
      xhr.setRequestHeader('Accept', 'application/json');
      xhr.setRequestHeader('Accept-Language', 'nl');
   }
});

A call to "/api/episerver/v2.0/site" does work:

// jQuery
$.ajax({
   url: "/api/episerver/v2.0/site",
   type: "GET",
   beforeSend: function(xhr){
      xhr.setRequestHeader('Accept', 'application/json');
      xhr.setRequestHeader('Accept-Language', 'nl');
   }
});

I know that the content delivery api also generated 404 responses if the content is not found or maybe in some other cases, but I don't think this is the case. I added the following to make sure the request was handled by a route:

// Global.asax.cs
public override void Init()
{
    base.Init();
    this.AcquireRequestState += ShowRouteValues;
}
protected void ShowRouteValues(object sender, EventArgs e)
{
    var context = System.Web.HttpContext.Current;
    if (context == null)
        return;
    var routeData = RouteTable.Routes.GetRouteData(new System.Web.HttpContextWrapper(context));
    // routeData can now be inspected with the debugger
}

When inspecting routeData after a JavaScript call to "/api/episerver/v2.0/content" routeData is null. When I explicitly add a route for this URL the routeData is not null:

protected override void RegisterRoutes(RouteCollection routes)
{
    base.RegisterRoutes(routes);
    routes.MapRoute("test", "api/episerver/v2.0/content", new {
        controller = "ContentApi",
    });
    // ...
}

When I make an override controller in my own code where I just call the base everywhere and set the same attributes when everything works fine.

To me it seems that the Route attributes in the ContentApiController class in the EPiServer.ContentDeliveryApi.CMS assembly are not found, but the strange thing is dat the sibling controller (SiteDefinitionApiController) is.

Anyone any ideas on how to get the routes for the content delivery api to work?

Thanks!


Viewing all articles
Browse latest Browse all 9076

Trending Articles