次の2つのルートルールを一緒に使用できますか?
_config.Routes.MapHttpRoute(
name: "ActionApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional } );
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
_
コントローラーごとに= _FruitApiController:ApiController
_と言うと、次のものが欲しい
List<Fruit> Get()
= _api/FruitApi/
_
List<Fruit> GetSeasonalFruits()
= _api/FruitApi/GetSeasonalFruit
_
Fruit GetFruits(string id)
= _api/FruitApi/15
_
Fruit GetFruitsByName(string name)
= _api/FruitApi/GetFruitsByName/Apple
_
これで私を助けてください。ありがとう
いくつかのルートがあります。
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.Routes.MapHttpRoute(
name: "ApiById",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional },
constraints: new { id = @"^[0-9]+$" }
);
config.Routes.MapHttpRoute(
name: "ApiByName",
routeTemplate: "api/{controller}/{action}/{name}",
defaults: null,
constraints: new { name = @"^[a-z]+$" }
);
config.Routes.MapHttpRoute(
name: "ApiByAction",
routeTemplate: "api/{controller}/{action}",
defaults: new { action = "Get" }
);
}
}
config.Routes.MapHttpRoute(
name: "ApiByName",
routeTemplate: "api/{controller}/{action}/{name}",
defaults: null,
constraints: new { name = @"^[a-z]+$" }
);