Created
February 4, 2019 11:29
-
-
Save warrenbuckley/b372c7576005593799c2a77c93e5df7a to your computer and use it in GitHub Desktop.
How to register & use WebAPI with Attribute Routes in Umbraco V8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Web.Http; | |
using Umbraco.Core; | |
using Umbraco.Core.Components; | |
namespace My.Website | |
{ | |
[RuntimeLevel(MinLevel = RuntimeLevel.Run)] | |
public class ApiComposer : IUserComposer | |
{ | |
public void Compose(Composition composition) | |
{ | |
composition.Components().Append<ApiComponent>(); | |
} | |
} | |
public class ApiComponent : IComponent | |
{ | |
public void Initialize() | |
{ | |
GlobalConfiguration.Configuration.MapHttpAttributeRoutes(); | |
} | |
public void Terminate() | |
{ | |
} | |
} | |
public class OrdersController : ApiController | |
{ | |
[Route("customers/{customerId}/orders")] | |
[HttpGet] | |
public string FindOrdersByCustomer(int customerId) | |
{ | |
return $"Fetching orders for {customerId} who has XX orders"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment