Skip to content

Instantly share code, notes, and snippets.

@skttl
Created January 22, 2019 19:19
Show Gist options
  • Save skttl/f30d95438de37fe11304c88860287001 to your computer and use it in GitHub Desktop.
Save skttl/f30d95438de37fe11304c88860287001 to your computer and use it in GitHub Desktop.
Attribute routing for Umbraco API Controller
// https://our.umbraco.com/forum/extending-umbraco-and-using-the-api/86507-can-i-use-rout-attributes-in-umbraco-controllers#
[RoutePrefix("api/v1/products")]
public class ProductsController : UmbracoApiController
{
[Route("")]
public List<Product> GetAllProducts()
{
return null;
}
[Route("{productId}")]
public Product GetProduct(int productId)
{
// Throw a clean exception
throw new HttpResponseException(new HttpResponseMessage
{
StatusCode = HttpStatusCode.BadRequest,
Content = new StringContent("not written")
});
}
[Route("{productId}/sources")]
public List<Source> ListProductSources(int productId)
{
return null;
}
[Route("{productId}/sources/{sourceId}")]
public Source GetProductSource(int productId, int sourceId)
{
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment