URL : /customers/1/orders
[Route("customers/{customerId}/orders")]
public IEnumerable<Order> GetOrdersByCustomer(int customerId)
{ ... }
(1)Enabling Attribute Routing
(2)Convention-based
public static class WebApiConfig { public static void Register(HttpConfiguration config) { // Attribute routing. config.MapHttpAttributeRoutes(); (1) // Convention-based routing. config.Routes.MapHttpRoute( (2) name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); } }
No comments:
Post a Comment