You can enable Attribute Routing to achieve something like this. Depending on your requirements you can either set the RoutePrefix at a controller level, or you can set routes on a per action basis.
You'll need a composer/component (I can't remember if you need one or both off the top of my head), in order to enable attribute routing.
I'll try and pop back tomorrow and share some sample code but this might point you in the right direction initially.
[RuntimeLevel(MinLevel = RuntimeLevel.Run)]
public class AttributeRoutingComposer : IUserComposer
{
public void Compose(Composition composition)
{
composition.Components().Insert<AttributeRoutingComponent>();
}
}
Component
public class AttributeRoutingComponent : IComponent
{
public AttributeRoutingComponent()
{
GlobalConfiguration.Configuration.MapHttpAttributeRoutes();
}
public void Initialize()
{
}
public void Terminate()
{
}
}
Then you can have an API controller that looks like this:
public class MyApiController : UmbracoApiController
{
[Route("/api/v1/feed/basic")]
public object MyEndPoint()
{
}
}
This would then be accessible on the url /api/v1/feed/basic
WebApi controllers without umbraco/api
I have a legacy webapi SomeController that I have to integrate to umbraco front end.
It is working changing inheritance from ApiController to Umbraco.Web.WebApi.UmbracoApiController
and calling it with umbraco/api/Some instead of api/Some
Is there any way to call it without umbraco/ ?
E.g. api/Some/MyAction ?
Thanks!
Hi Nicolas,
You can enable Attribute Routing to achieve something like this. Depending on your requirements you can either set the RoutePrefix at a controller level, or you can set routes on a per action basis.
You'll need a composer/component (I can't remember if you need one or both off the top of my head), in order to enable attribute routing.
I'll try and pop back tomorrow and share some sample code but this might point you in the right direction initially.
Cheers
Nik
Hi Nicolas,
As mentioned here is some sample code:
Composer
Component
Then you can have an API controller that looks like this:
This would then be accessible on the url
/api/v1/feed/basic
Hope that helps :-)
Nik
is working on a reply...