Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What http status code to return for "invalid state change"

This is a question about best REST practices. Considering the controller below which has a method which is supposed to update an application object.

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();
    }
}

What status code would be best to return if it is not possible to change the state of the application to the new state?

like image 784
mortb Avatar asked Sep 13 '17 10:09

mortb


1 Answers

Have look here https://martinfowler.com/articles/richardsonMaturityModel.html in the level 3 section

Fowler uses a 409 Conflict header to indicate that something went wrong.

like image 90
Torsten Avatar answered Sep 17 '22 08:09

Torsten