HTTP PATCH 是否仅限于一次只修改一个字段?
Is HTTP PATCH restricted to modifying only one field at a time?
HTTP PATCH
方法是否限制一次只能更新一个字段?我可以修改 PATCH
请求中的多个字段吗? PATCH
可以修改所有字段吗?
Does HTTP PATCH
method restrict updates to only one field at a time?
没有
Can I modify more than one field in a PATCH
request?
当然可以。
Can PATCH
be used for modifying all the fields?
是的。但是您可以考虑 PUT
用于此目的。而且,根据您的需要,您可以考虑在 API.
中支持 PATCH
和 PUT
PATCH
method definition doesn’t enforce any format for the request payload apart from mentioning that the request payload should contain a set of instructions describing how the resource will be modified and that set of instructions is identified by a media type (which defines how the PATCH
应由服务器应用。
来自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. […]
描述此类更改的一些合适的格式是:
- JSON Patch (
application/json-patch+json
)
- JSON Merge Patch (
application/merge-patch+json
)
我在此 along with a comparison with PUT
中添加了有关每种格式的更多详细信息。所以我强烈建议你看看。
HTTP PATCH
方法是否限制一次只能更新一个字段?我可以修改 PATCH
请求中的多个字段吗? PATCH
可以修改所有字段吗?
Does HTTP
PATCH
method restrict updates to only one field at a time?
没有
Can I modify more than one field in a
PATCH
request?
当然可以。
Can
PATCH
be used for modifying all the fields?
是的。但是您可以考虑 PUT
用于此目的。而且,根据您的需要,您可以考虑在 API.
PATCH
和 PUT
PATCH
method definition doesn’t enforce any format for the request payload apart from mentioning that the request payload should contain a set of instructions describing how the resource will be modified and that set of instructions is identified by a media type (which defines how the PATCH
应由服务器应用。
来自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. […]
描述此类更改的一些合适的格式是:
- JSON Patch (
application/json-patch+json
) - JSON Merge Patch (
application/merge-patch+json
)
我在此 PUT
中添加了有关每种格式的更多详细信息。所以我强烈建议你看看。