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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With