Rest best practice: when to return 404 not found

后端 未结 1 1575
感动是毒
感动是毒 2021-01-21 17:27

If I have the following rest call:

GET /items/{id}/subitems

Should we return the following in these scenarios?:

  1. If {id}
1条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-21 17:53

    For me the answer is yes for both questions.

    REST is about resources. If resource with given ID hasn't been found, then 404 Not Found is the most appropriate response status.

    But at the same time, GET /items/{id}/subitems/{subitem-id} should definitely return the HTTP 404 if subitem with given id doesn't exist.

    0 讨论(0)
提交回复
热议问题