我正在创建一个HTTP。在/base-url,我收集了大量的键值对。
我需要提供获取和设置键值的能力。
我第一次尝试:
GET /base-url/{key}
PUT /base-url/{key}问题是,这需要URL菜谱,据我所知,这违背了REST的超媒体原则。
通过RESTful API提供键值存储的通常方法是什么?
发布于 2014-11-21 22:42:11
只要您的{key} URL是可发现的,REST就允许这样做;例如,如果执行
GET /base-url/返回指向其他有效REST资源的链接列表,其中包括/base-url/{key}
主要的一点是,符合REST的API不需要带外知识;但是如果提供者发布规范,客户机当然可以直接访问它已经知道的URL。
我发现罗伊·菲尔丁( Roy )的这篇文章对澄清这些问题非常有用,特别是
A REST API must not define fixed resource names or hierarchies (an obvious coupling
of client and server). Servers must have the freedom to control their own namespace.
Instead, allow servers to instruct clients on how to construct appropriate URIs, such
as is done in HTML forms and URI templates, by defining those instructions within
media types and link relations. [Failure here implies that clients are assuming a
resource structure due to out-of band information, such as a domain-specific standard,
which is the data-oriented equivalent to RPC's functional coupling].这实际上意味着,如果您发布了一个规范,而客户机/程序员需要它来确定有效的URL,那么您已经创建了一个API,但它不是REST。要符合Roy定义REST的论点,您必须从根开始就可以发现相同的URL。
https://softwareengineering.stackexchange.com/questions/263470
复制相似问题