我将构建以下WEB Api:
api/voyages [params]
api/voyages/1234
api/voyages/1234/itinerary
api/voyage/1234,6789/inventory [params]
api/voyages/1234,6789/cabin [params]
您能帮我正确配置文件 WebApiConfig.cs, Global.asax.cs
和控制器吗?
提前致谢
的Davide
答案 0 :(得分:1)
使用AttributeRouting,无需配置太多; - )
对于你的控制器,你只需添加:
[RoutePrefix("api/voyages")]
public class VoyagesController : ApiController
{
[HttpGet]
[Route("{id:int}")]
public HttpAction GetVoyage(id)
{
}
[HttpGet]
[Route("{id:int}\itinerary")]
public HttpAction GetVoyage(id)
{
}
}