Skip to content

Instantly share code, notes, and snippets.

@warrenbuckley
Created February 4, 2019 11:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save warrenbuckley/b372c7576005593799c2a77c93e5df7a to your computer and use it in GitHub Desktop.
Save warrenbuckley/b372c7576005593799c2a77c93e5df7a to your computer and use it in GitHub Desktop.
How to register & use WebAPI with Attribute Routes in Umbraco V8
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