1
所以一個典型的crud會是這樣的。很多很多crud請求
[Route("api/[controller]")]
public class ProvidersController : Controller {
[HttpGet]
public IEnumerable<object> Get(){}
[HttpGet("{id}")]
public IActionResult Get(int id) {}
// POST api/provider
[HttpPost]
public IActionResult Post([FromBody]Provider value){}
// PUT api/provider/5
[HttpPut("{id}")]
public IActionResult Put(int id, [FromBody]Provider value){}
// DELETE api/provider/5
[HttpDelete("{id}")]
public IActionResult Delete(int id) {}
}
但是我想將它擴展爲多對多的類型資源。
我在哪裏有路徑/ api/provider/{id}/resolution [GET,POST,PUT,DELETE]。
我在不同的班級做這個或者我是否擴展這個?我可以將它添加到這個類嗎?
我試圖做下面的事情,但它似乎不應該在同一類。
[Route("api/[controller]")]
public class ProvidersController : Controller {
[HttpGet]
public IEnumerable<object> Get(){}
[HttpGet("{id}")]
public IActionResult Get(int id) {}
// POST api/provider
[HttpPost]
public IActionResult Post([FromBody]Provider value){}
// PUT api/provider/5
[HttpPut("{id}")]
public IActionResult Put(int id, [FromBody]Provider value){}
// DELETE api/provider/5
[HttpDelete("{id}")]
public IActionResult Delete(int id) {}
Route["{providerId}/resources/"]
public IEnumerable<object> Get(int providerId){}
Route["{providerId}/resources/{id}"]
public IActionResult<object> Get(int providerId, int id){}
}
所以如果我將它移動到另一個控制器,路線將如何顯示? [Route(「api/provider/{providerId}/[controller]」)] public class OtherController:Controller {? –
api/resource/{providerId}/{id} –