HTTP GET Request Status 204 Vs 404

后端 未结 5 787
北海茫月
北海茫月 2020-12-25 11:06

I have 2 resources User and Album. An user has a list of albums. To get albums there are 2 REST API.

  1. user/{userId}/albums/{albumId} get album by albumId if not
5条回答
  •  Happy的楠姐
    2020-12-25 12:03

    I agree with the responses, but I think is 204 or 200, it depends of your response when the album list is empty.

    If you will return a empty array, the return it with 200 code, if you prefer to don't return anything, then the right one will be 204. (I prefer a 200 with empty list)

    Only use 404 with a resource doesn't existis, if it is a empty list the choose 204 or 200.

    Good hacking man!

提交回复
热议问题