ruby-on-rails - rails api 中被阻止的用户配置文件的最佳 HTTP 状态代码是什么?

标签 ruby-on-rails api http

我在 Rails 中为社交应用程序编写了一个 API。这个应用程序喜欢 Facebook,用户可以阻止其他用户。如果用户 A 阻止用户 B,则用户 B 无法查看用户 A 的个人资料页面。那么我应该返回的最佳 HTTP 代码状态是什么:404、403、204 或 200(不显示任何内容)?

最佳答案

我更喜欢使用 403 Forbidden

The 403 (Forbidden) status code indicates that the server understood the request but refuses to authorize it. A server that wishes to make public why the request has been forbidden can describe that reason in the response payload (if any).

If authentication credentials were provided in the request, the server considers them insufficient to grant access. The client SHOULD NOT automatically repeat the request with the same credentials. The client MAY repeat the request with new or different credentials. However, a request might be forbidden for reasons unrelated to the credentials.

An origin server that wishes to "hide" the current existence of a forbidden target resource MAY instead respond with a status code of 404 (Not Found).

https://www.rfc-editor.org/rfc/rfc7231#section-6.5.3

关于ruby-on-rails - rails api 中被阻止的用户配置文件的最佳 HTTP 状态代码是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41332740/

相关文章:

ruby-on-rails - 使用第三方服务本地主机子域是否存在安全风险?

PHP域whois脚本不返回所有信息

c++ - 像 ListView 这样的资源管理器

http - 如何使用 HTTPie 发送 POST 请求?

python - 在 Python 的 POST http header 中检索 HTML 表单数据

ruby-on-rails - Rails 4 中的 Post 与 Post_via_redirect 未按预期方式运行

ruby-on-rails - 如何在 Rails 6 中使用 Webpacker 跨多个客户端 JavaScript 文件共享变量和函数?

ruby-on-rails - 简单的 cucumber 测试问题

javascript - 如何使用 Facebook Graph API 对 Facebook POST 点赞?

java - UrlConnection.getHeaderField(字符串名称) 返回 null