首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >RESTful键值收集

RESTful键值收集
EN

Software Engineering用户
提问于 2014-11-21 20:10:54
回答 1查看 2.2K关注 0票数 4

我正在创建一个HTTP。在/base-url,我收集了大量的键值对。

我需要提供获取和设置键值的能力。

我第一次尝试:

代码语言:javascript
复制
GET /base-url/{key}

PUT /base-url/{key}

问题是,这需要URL菜谱,据我所知,这违背了REST的超媒体原则。

通过RESTful API提供键值存储的通常方法是什么?

EN

回答 1

Software Engineering用户

发布于 2014-11-21 22:42:11

只要您的{key} URL是可发现的,REST就允许这样做;例如,如果执行

代码语言:javascript
复制
GET /base-url/

返回指向其他有效REST资源的链接列表,其中包括/base-url/{key}

主要的一点是,符合REST的API不需要带外知识;但是如果提供者发布规范,客户机当然可以直接访问它已经知道的URL。

我发现罗伊·菲尔丁( Roy )的这篇文章对澄清这些问题非常有用,特别是

代码语言:javascript
复制
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。

票数 6
EN
页面原文内容由Software Engineering提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://softwareengineering.stackexchange.com/questions/263470

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档