Created
January 22, 2019 19:19
-
-
Save skttl/f30d95438de37fe11304c88860287001 to your computer and use it in GitHub Desktop.
Attribute routing for Umbraco API Controller
This file contains hidden or 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
// 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