Correct HTTP status code when resource is available but not accessible because of permissions

后端 未结 4 1437
被撕碎了的回忆
被撕碎了的回忆 2020-12-20 12:18

I am building a RESTful protocol for Dynamic Carpooling applications, for my Computer Science thesis.

In the Protocol I also have to formally specify the HTTP statu

相关标签:
4条回答
  • 2020-12-20 12:23

    Definitely NOT 404. 404 is just Not Found.
    401 is access denied.
    403 is forbidden.

    I would go with 401

    0 讨论(0)
  • 2020-12-20 12:24

    According to Wikipedia (and RFC 2616), a 401 code is used when a page exists but requires authentication; 403 is for a page where authenticating won't change anything. (In the wild, 403 usually means the permissions on something are wrong, whereas a 401 will prompt the user for a username/password). 404 is for where the document simply doesn't exist.

    In your case, it seems like 401 is the most appropriate code, since there is some way of authenticating the users who DO have access to the page.

    0 讨论(0)
  • 2020-12-20 12:26

    To me I will use 400 Bad request.
    Because my application will not go unaccessable resources in programmatically.
    Filtering users permission and hide unaccessable resources is good user experience in my opinion. If my server got unaccessable request which means some person trying to do something.
    That is why I choose 400 - Bad request in my applications.

    0 讨论(0)
  • 2020-12-20 12:42

    If authorization credentials are provided in the request and the requester does not have permissions to access this resource then you should return 403.

    If no authorization credentials are provided in the request then you should return 401.

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