1

Hi i have written a rest service to delete multiple files and i am trying to access the rest service. My input to rest service will be List values which will be id of files that needs to be deleted. For that i have written the below code

    List<Long> ids=new ArrayList<Long>();
    ids.add(4l);
    ids.add(5l);

    boolean status = false;
    String jsonResponse = null;
    DefaultHttpClient httpClient = null;
    HttpResponse response = null;
    try {
        httpClient = new DefaultHttpClient();

        StringBuilder url = new StringBuilder("http://localhost:8080/api/files");
        URIBuilder builder = new URIBuilder();
        URI uri = builder.build();

        HttpDelete deleteRequest = new HttpDelete(uri);

        //how to set list as Requestbody and send

        response = httpClient.execute(deleteRequest);
    } 

Here i dont know how to set List as entity in request body and send. Can someone help me on this

krishna
  • 343
  • 2
  • 5
  • 19
  • Possible duplicate of [Java HTTP DELETE with Request Body](https://stackoverflow.com/questions/43241436/java-http-delete-with-request-body) – Sambit Jul 31 '19 at 07:46

1 Answers1

0

A HTTP DELETE request should delete the resource identified by the URI. The body is not relevant. To delete a single resource:

DELETE /api/files/123

If you want to delete more than one file in a single request, model a collection of files as a resource. This could be done by listing more than one ID in the URL:

GET /api/files/123,456,789

This could return a JSON array with the details of the three files.

To delete these three files, execute a DELETE request agains the same URL:

DELETE /api/files/123,456,789