How to overloading or change name to /umbraco/api/ route?
Is't possibile change the name or add an alternative URL routing for Umbraco API Controller ( controller with UmbracoApiController )?
That is:
Normal: /umbraco/api/
I think if I understand correctly you might want to use Web API attribute routes to change the urls for your api endpoint?
Something like this?
using System.Collections.Generic;
using System.Web.Http;
using Umbraco.Web.WebApi;
namespace Umbraco8.Controllers
{
public class MyCustomApiController : UmbracoApiController
{
[HttpGet]
[Route("umbraco/api/things")]
public IEnumerable<string> GetThings)
{
return new[] { "Table", "Chair", "Desk", "Computer", "Beer fridge" };
}
}
}
which would make the url:
/umbraco/api/things to return the list provided by GetThings endpoint
For this to work you'd need to call MapHttpAttributeRoutes method as Umbraco starts up, if you add a class that inherits IComponent you can call this method on Initialize() and add another class inheriting IComposer to run the Component at start-up eg:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Routing;
using Umbraco.Core.Composing;
using Umbraco.Web;
using Umbraco.Web.Mvc;
namespace Umbraco8.Components
{
[RuntimeLevel(MinLevel = RuntimeLevel.Run)]
public class RegisterCustomApiRoutesComposer : IComposer
{
composition.Components().Insert<RegisterCustomApiRoutesComponent>();
}
public class RegisterCustomApiRoutesComponent : IComponent
{
public void Initialize()
{
GlobalConfiguration.Configuration.MapHttpAttributeRoutes();
}
public void Terminate()
{
throw new NotImplementedException();
}
}
}
How to overloading or change name to /umbraco/api/ route?
Is't possibile change the name or add an alternative URL routing for Umbraco API Controller ( controller with UmbracoApiController )? That is: Normal: /umbraco/api/
Thanks
Hi Biagio
I think if I understand correctly you might want to use Web API attribute routes to change the urls for your api endpoint?
Something like this?
which would make the url:
/umbraco/api/things to return the list provided by GetThings endpoint
For this to work you'd need to call MapHttpAttributeRoutes method as Umbraco starts up, if you add a class that inherits IComponent you can call this method on Initialize() and add another class inheriting IComposer to run the Component at start-up eg:
regards
Marc
is working on a reply...