Umbraco 8 Changing the default route of UmbracoApiController
I am working with UmbracoApiController and I want to change the default path to be something more friendly and more importantly not contain the "umbraco/api" stuff.
so my controller is call
public class ResidenceApiController : _BaseWebApiController
{
}
I want to make the path to the API something like this....
Look at the bottom...
Using MVC Attribute Routing in Umbraco Web API Controllers
Basically add these two classes to your project
public class AttributeRoutingComponent : IComponent
{
public void Initialize()
{
GlobalConfiguration.Configuration.MapHttpAttributeRoutes();
}
public void Terminate()
{
}
}
[RuntimeLevel(MinLevel = RuntimeLevel.Run)]
public class AttributeRoutingComposer : IComposer
{
public void Compose(Composition composition)
{
composition.Components().Insert<AttributeRoutingComponent>(); ;
}
}
Then your API Method might look something like this..
[HttpGet]
[Route("residence/api/getall")]
public TestDataDto GetAll()
{
TestDataDto TestDataDto = new TestDataDto();
TestDataDto.TestString = "this is a test";
TestDataDto.AnotherTestString = "this is a another test";
TestDataDto.TestInt = 99;
TestDataDto.TestBool = true;
return TestDataDto;
}
Umbraco 8 Changing the default route of UmbracoApiController
I am working with UmbracoApiController and I want to change the default path to be something more friendly and more importantly not contain the "umbraco/api" stuff.
so my controller is call
public class ResidenceApiController : _BaseWebApiController {
}
I want to make the path to the API something like this....
/residence/api/getall
Does anyone know if this is possible?
Thanks in advance
Hi Nathan,
Yes this is possible. There is a good tutorial here. https://our.umbraco.com/documentation/reference/routing/webapi/
Look at the bottom... Using MVC Attribute Routing in Umbraco Web API Controllers
Basically add these two classes to your project
Then your API Method might look something like this..
Regards
David
Awesome,
Thanks a bunch.
is working on a reply...