web-services - 使用魔术(我/自己)资源标识符是否违反REST原则?

标签 web-services rest restful-url

我已经看到了支持经过身份验证的用户的魔术id的URI,如下所示:

GET /user/me - list my profile
GET /user/me/photos - list my photos

下面的使用实际的用户ID
GET /user/742924
GET /user/742924/photos

我看到的问题是,根据身份验证的用户,相同的资源ID指向不同的资源。

这违反任何REST原则吗?

最佳答案

从REST的 Angular 来看,使用/me命名与已认证用户相对应的资源是完全可以的。根据Roy Thomas Fielding的论文,可以命名的任何信息都可以是资源:

5.2.1.1 Resources and Resource Identifiers

The key abstraction of information in REST is a resource. Any information that can be named can be a resource: a document or image, a temporal service (e.g. "today's weather in Los Angeles"), a collection of other resources, a non-virtual object (e.g. a person), and so on. In other words, any concept that might be the target of an author's hypertext reference must fit within the definition of a resource. A resource is a conceptual mapping to a set of entities, not the entity that corresponds to the mapping at any particular point in time. [...]



使用/me时,您有一个用于身份验证用户的定位器,它将始终标识身份验证用户的概念,而不管哪个用户被身份验证。

关于web-services - 使用魔术(我/自己)资源标识符是否违反REST原则?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35719797/

相关文章:

java - 学习 RESTful Web 服务之前有什么先决条件吗?

web-services - 如何使用 spring3 保护服务 REST?

java - 如何将我的 RESTful 应用程序部署到 Apache 服务器?

rest - CSV 的替代品?

ruby-on-rails-3 - 传递 :new to Rails url_for

node.js - 如何指定xsi :type for an element in SOAP request using node-soap

java - 如何获得对改造异常的响应体?

rest - REST 架构中的分页

java - Spring 休息 : when pathVariable matches multiple entities should spring return a list or throw error

java - 在 Java 中编写和追加大文件的最佳方法是什么