Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 240
SB2055 Avatar asked Jul 07 '13 20:07

SB2055


2 Answers

[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]
like image 62
Darin Dimitrov Avatar answered Oct 03 '22 18:10

Darin Dimitrov


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

api call

DELETE /api/Folder?ids=1&ids=2
like image 32
ckross01 Avatar answered Oct 03 '22 18:10

ckross01