Home > Mobile >  Appropriate HTTP Error Code for PUT Requests
Appropriate HTTP Error Code for PUT Requests

Time:09-06

I have an application where a user can create several schedules from a list of events. Each item added to a schedule can be updated(or edited).

Assume Schedule 1 contains Event 1 and Event 2 and Schedule 2 contains Event 3 and Event 4.

The endpoint to update an item in a schedule is /api/{scheduleNumber}/{eventId}

Now if the user sends a PUT request to the endpoint /api/{1}/{3}, with a properly formed body about the updated event, this is obviously wrong since Schedule 1 does not contain Event 3.

In this situation, is it appropriate to send 400 Bad Request, assuming that the request has a valid syntax?

CodePudding user response:

I would argue that 404 Not Found as response for not found resource can be preferable approach and it is applicable in this case since no Event 3 for Schedule 1 exists. And it would be better/more clear if combined with recommended "use logical nesting on endpoints" approach.

  • Related