【发布时间】:2014-07-04 15:49:12
【问题描述】:
我有 rest url 支持 POST 请求。它看起来像
api/country/{countryId}/state
用于在具有给定 ID 的 国家 中创建 state 资源
但是这个url的映射函数是
public HttpResponseMessage Post(int countryId,StateDto state)
{
var country = _countryAppService.AddNewState(state, countryId);
var message = Request.CreateResponse(HttpStatusCode.Created, country);
return message;
}
给定网址的预期样本就像 api/country/1/state(在国家/地区创建一个 id=1 的新州)
但是这里我没有使用上述函数中的url值(1),而不是调用者需要通过请求体传递相应的countryId,即不能保证url中的contryId和post请求相同.所以我的疑问是什么是正确的 url 模式来保存特定国家/地区的状态 vai post request?
【问题讨论】:
标签: asp.net-mvc rest asp.net-web-api asp.net-web-api2