gpt4 book ai didi

http-patch - 根据 HTTP PATCH RFC,文档的部分表示是否为有效的 "set of changes"?

转载 作者:行者123 更新时间:2023-12-03 09:34:53 28 4
gpt4 key购买 nike

这是什么RFC 5789说:

The PATCH method requests that a set of changes described in the request entity be applied to the resource identified by the Request-URI. The set of changes is represented in a format called a "patch document" identified by a media type. If the Request-URI does not point to an existing resource, the server MAY create a new resource, depending on the patch document type (whether it can logically modify a null resource) and permissions, etc.

The difference between the PUT and PATCH requests is reflected in the way the server processes the enclosed entity to modify the resource identified by the Request-URI. In a PUT request, the enclosed entity is considered to be a modified version of the resource stored on the origin server, and the client is requesting that the stored version be replaced. With PATCH, however, the enclosed entity contains a set of instructions describing how a resource currently residing on the origin server should be modified to produce a new version.


假设我有 { "login": "x", "enabled": true } ,我想禁用它。
根据帖子 "Please. Don't Patch Like An Idiot." ,正确的 PATCH 请求是
[{ "op": "replace", "path": "/enabled", "value": false }]
但是,让我们接受这个请求:
{ "enabled": false }
它还“包含一组描述当前驻留在源服务器上的资源应该如何修改的指令”,唯一的区别是使用 JSON 属性而不是 JSON 对象。
它似乎不那么强大,但是如果需要,数组更改可以有一些其他特殊语法(例如 {"a":{"add":[], "remove":[]}} ),并且服务器逻辑无论如何都可能无法处理任何更强大的东西。
根据 RFC,这是一个不正确的 PATCH 请求吗?如果是这样,为什么?
并且,另一方面,会是 { "op": "disable" }是正确的 PATCH 请求?

最佳答案

the only difference is that JSON property is used instead of JSON object.


它实际上比这更深一些。引用 RFC 6902很重要。第一个请求有一个 Content-Typeapplication/json-patch+json ,但第二个是 application/json重要的是你使用了一种“差异媒体类型”,一种对这个目的很有用的。您不必使用 JSON-PATCH,(我是 json-merge-patch 的忠实粉丝),但您不能只使用您想要的任何东西。您在第二部分问的基本上是“我可以制作自己的媒体类型吗”,答案是“可以”,只需将其记录下来并在 IANA 中注册即可。

关于http-patch - 根据 HTTP PATCH RFC,文档的部分表示是否为有效的 "set of changes"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25635213/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com