要为“无效状态更改”返回什么http状态代码

时间:2017-09-13 10:34:57

标签: c# rest asp.net-core

这是关于最佳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();
    }
}

如果无法将应用程序的状态更改为新状态,最好返回什么状态代码?

1 个答案:

答案 0 :(得分:1)

请在第3级

中查看https://martinfowler.com/articles/richardsonMaturityModel.html

Fowler使用409 Conflict标头表示出现了问题。