这是关于最佳REST实践的问题。 考虑下面的控制器有一个应该更新应用程序对象的方法。
public ApplicationController : Controller
{
private readonly ApplicationService _applicationService;
public ApplicationController(ApplicationService applicationService)
{
_applicationService = applicationService;
}
[HttpPost]
public IActionResult Post([FromBodey] Application application)
{
var previousApplication = _applicationService.Get(applicationId)
if(application.State == ApplicationState.Approved
&& apreviousApplcation.State != ApplicationState.Pending)
{
return StatusCode(*what code here*, "State have to be pending to goto approved");
}
_applicationSerivce.Update(application);
return Ok();
}
}
如果无法将应用程序的状态更改为新状态,最好返回什么状态代码?
答案 0 :(得分:1)
请在第3级
中查看https://martinfowler.com/articles/richardsonMaturityModel.htmlFowler使用409 Conflict标头表示出现了问题。