Search code examples
javahttpjax-rshttp-method

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


I have to build JAX-RS web service, which will delete client from client resource, plus it should have external uuid in request.

the implementation of @DELETE method without externalId is very simple

/myService/client/1


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

        // implementation code 

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

but where should I add externalId as @QueryParam?

in case @QueryParam the URI will be this, is it correct design?

/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();
        }

or maybe I should send externalId in to request body or as @PatchParam?

which will be correct design?

should I use another HTTP Method instead of HTTP DELETE for this case?


Solution

  • Sending two information to identify a resource to delete is not conventional.
    It doesn't mean that it is forbidden but you should be aware of it.

    Adding this information in the body ?
    Servers may ignore body for delete requests.

    Suffixed this information in the path ?
    It breaks the semantic of the path that should be a way to identify naturally a resource in the hierarchy/resource structure.

    I think that you actual way with @QueryParam is an acceptable workaround if you have the constraint to convey these two information and that really you cannot change it.
    As alternative you can also use URL matrix parameters to convey a composite id
    such as DELETE /myService/client/1,123456 where 1 is the client id and 123456 the uuid