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.

2
  • Why cant you provide the IDs as URL parameters? Commented Jun 16, 2018 at 23:09
  • 1
    because i don't know how many objects the user is going to delete. I'm showing a list of things and the user select the ones that he want to delete. Commented Jun 16, 2018 at 23:26

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

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.
Thank you so much, i can access to the array with the next parameter : [FromBody] ids
I have the next problem: stackoverflow.com/questions/50893637/… can you help me?
RequestOptions was depredacted with the whole @angular/http package since Angular 5. Options now are only an object without specific type.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.