HATEOAS与PUT/POST链接 [英] HATEOAS links with PUT/POST

查看:68
本文介绍了HATEOAS与PUT/POST链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为资源上的 POST / PUT / PATCH 表示HATEOAS链接的最佳方法是什么?这些操作具有有效负载,但是我们没有选择在HATEOAS链接中表示有效负载的选项,因为它们不是预先确定的,而且可能很重.那么仅指定终点并指定操作就足够了吗?

What would be the best way to represent a HATEOAS link for a POST/PUT/PATCH on a resource? These operations have payload but we won't have an option to represent the payload in HATEOAS link as they aren't predetermined and can be heavy. So would it suffice just specifying the end point and specifying the operation?

对于使用HATEOAS POST / PUT / PATCH 链接的JSON响应,任何示例或示例都将不胜感激.

Any samples or examples would be greatly appreciated for a JSON response with HATEOAS POST/PUT/PATCH link.

推荐答案

链接由两个元素组成: href rel . href 包含用于定位资源的显式URL. rel 标识当前资源和链接资源之间的关系.应该使用 rel 来确定可接受的HTTP方法以及如何使用链接.

Links are comprised of two elements: href and rel. The href contains the explicit URL to locate a resource. The rel identifies the relationship between the current resource and the link's resource. The rel should be used to determine what HTTP method is acceptable and how the link should be used.

以下是 RESTful Web服务指南第5.4节的引文:

The following is a quote from RESTful Web Services Cookbook section 5.4:

链接关系类型传达了链接的作用或目的.一旦客户端和服务器就这些类型的含义达成一致,客户端就可以从链接中查找和使用URI.

A link relation type conveys the role or purpose of a link. Once clients and servers agree on the meaning of these types, clients can find and use URIs from links.

例如, edit 标准具有显式详细信息的链接关系,包括有关使用 GET , PUT POST Delete .

For example, edit is a standard link relation that has explicit details including details around using GET, PUT, POST, DELETE.

可以扩展链接关系,也可以添加自己的链接.

Link relations can be extended and you can add your own.

这篇关于HATEOAS与PUT/POST链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆