0

I'm trying to make a massive delete, in order to do that I have an Array<number> of the ids I want to delete. I can't pass this array as a parameter to the method this._httpService.delete(uri,options). The type of _httpService is Http.

So I'm looping the array and inside the loop I'm making single calls, but each call is async and I have certain logic to run when the loop ends.

Marcos Dimitrio
  • 6,651
  • 5
  • 38
  • 62
Daniel Acevedo
  • 79
  • 1
  • 1
  • 11

1 Answers1

2

Actually you can send the id array in the body of a DELETE request, according to this answer, like so:

http.delete('/api/something', new RequestOptions({
    headers: headers,
    body: anyObject    // this would contain your ids
}))

So instead of issuing hundreds of requests, have your app make just one with all ids in the body.

Marcos Dimitrio
  • 6,651
  • 5
  • 38
  • 62
  • Awsome, and my next question would be: how do i access to that array? I can access to the headers doing in mi backend : Request.Headers.Autrhorization.Scheme for example to get the token. – Daniel Acevedo Jun 17 '18 at 03:26
  • Thank you so much, i can access to the array with the next parameter : [FromBody] ids – Daniel Acevedo Jun 17 '18 at 03:36
  • I have the next problem: https://stackoverflow.com/questions/50893637/cant-access-to-my-method-delete-of-my-api-rest can you help me? – Daniel Acevedo Jun 17 '18 at 04:18
  • RequestOptions was depredacted with the whole @angular/http package since Angular 5. Options now are only an object without specific type. – jowey Feb 11 '20 at 08:14