SB2055
SB2055

Reputation: 12862

DELETE multiple IDs with WebAPI Delete Endpoint?

My webAPI solution currently works if I send a single id to the delete endpoint:

DELETE /api/object/1

With:

    [HttpDelete]
    public HttpResponseMessage DeleteFolder(int id)
    {
    // Do stuff
    }

In my client application I have a UI that allows for multiple deletes - right now it's just calling this endpoint in a loop for each one of the ids selected, which isn't super performant. I'd like to be able to send an array of Ids to the Delete method in this case... how can this be achieved?

Upvotes: 5

Views: 11577

Answers (2)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038730

[HttpDelete]
public HttpResponseMessage DeleteFolder(int[] ids)
{
    // Do stuff
}

and then you could send the following HTTP request:

DELETE /api/somecontroller HTTP/1.1
Accept: application/json
Content-Length: 7
Content-Type: application/json
Host: localhost:52996
Connection: close

[1,2,3]

Upvotes: 5

ckross01
ckross01

Reputation: 1671

[HttpDelete]
public HttpResponseMessage Folder([FromUri] int[] ids)
{
     //logic
}

api call

DELETE /api/Folder?ids=1&ids=2

Upvotes: 5

Related Questions