Link to home
Start Free TrialLog in
Avatar of cofactor
cofactor

asked on

RestService and RestTemplate

My Spiring  RestService delete method has signature :

public ResponseEntity<?> delete(@RequestBody List<Long> IdList)


Question :
I am making a client code and trying to send  list of  long id's to  my above service  with the help of  RestTemplate  delete .  But it seems RestTemplate delete method does not accept list of long ids . How to fix this ?

Here is the client code:

RestTemplate.delete("/bsi/extgd/v1" + [2,3,4]);  //  this does not work... as I cant send list of long ids here

Is there any way to send   list of long ids to delete method  ?
Avatar of cofactor
cofactor

ASKER

any comments ?
Avatar of mccarl
But it seems RestTemplate delete method does not accept list of long ids

This is because the HTTP DELETE method is generally not used with a request body at all, and so RestTemplate has no methods for passing any body content.

So the options are to just hack together a solution. It's probably easier but is less "RESTful" (that may or may not be important to you). Or if you are trying to adhere to the REST ideals, I would go with the idea of creating a new resource (i.e. with a POST call), and the resource is actually a list (or selection) of other resources. The server creates this list and then returns a generated id for this new list resource. Then you can DELETE this resource and it will delete the resources specified in the list. The source of the idea and other useful info is here.
ASKER CERTIFIED SOLUTION
Avatar of cofactor
cofactor

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
there was issue in adding correct data type which I rectified.