HTTP GET Request Status 204 Vs 404

后端 未结 5 795
北海茫月
北海茫月 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条回答
  •  半阙折子戏
    2020-12-25 12:04

    Error Code 404

    The web site hosting server will typically generate a "404 Not Found" web page when a user attempts to follow a broken or dead link.

    Return Code 204

    The server has fulfilled the request but does not need to return an entity-body.

    Conclusion

    You obviously need to return a 204 status code. If you use the 404 one, the user may be disturbed. More, you use 404 when the targeted album doesn't exist. Using 404 for both 1 and 2 is illogical.

提交回复
热议问题