将附加参数传递给 HTTP @DELETE 方法的正确方法是什么

what is the correct way to pass additional parameter to HTTP @DELETE method

我必须构建 JAX-RS Web 服务,这将从客户端资源中删除客户端,而且它应该在请求中具有外部 uuid。

没有externalId的@DELETE方法的实现很简单

/myService/client/1


@DELETE
    @Path("/client/{client}")
    public Response removeClient(@PathParam("client") long client) {

        // implementation code 

        return Response.status(200).build();
    }

但是我应该在哪里添加 externalId as @QueryParam

万一 @QueryParam URI 是这个,设计正确吗?

/myService/client/1?externalId=d852e3fc-b7ac-42d7-b22b-74cb4da709ec

  @DELETE
        @Path("/client/{client}")
        public Response removeClient(@PathParam("client") long client, @QueryParam("externalId") String externalId ) {

            // implementation code 

            return Response.status(200).build();
        }

或者我应该将 externalId 发送到 request body@PatchParam?

哪个设计是正确的?

对于这种情况,我应该使用其他 HTTP 方法而不是 HTTP DELETE 吗?

发送两条信息来识别要删除的资源是不常规的。
这并不意味着它是被禁止的,但你应该意识到这一点。

在正文中添加此信息?
服务器可能会忽略删除请求的正文。

在路径中添加此信息的后缀?
它打破了路径的语义,该路径应该是一种自然识别 hierarchy/resource 结构中资源的方法。

我认为如果您有传达这两个信息的约束并且真的您无法更改它,那么您使用@QueryParam的实际方式是一个可以接受的解决方法。
作为替代方案,您还可以使用 URL 矩阵参数来传达复合 id
例如 DELETE /myService/client/1,123456 其中 1 是客户端 ID,123456 是 uuid

来自 specification:

The DELETE method requests that the origin server delete the resource identified by the Request-URI. This method MAY be overridden by human intervention (or other means) on the origin server. The client cannot be guaranteed that the operation has been carried out, even if the status code returned from the origin server indicates that the action has been completed successfully. However, the server SHOULD NOT indicate success unless, at the time the response is given, it intends to delete the resource or move it to an inaccessible location.

A successful response SHOULD be 200 (OK) if the response includes an entity describing the status, 202 (Accepted) if the action has not yet been enacted, or 204 (No Content) if the action has been enacted but the response does not include an entity.

If the request passes through a cache and the Request-URI identifies one or more currently cached entities, those entries SHOULD be treated as stale. Responses to this method are not cacheable.

因此,没有任何关于参数传递的限制或建议。您可以根据需要使用任何方便的变体