DELETE multiple identifiers with WebAPI delete endpoint?

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

DELETE /api/object/1 

Via:

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

In my client application, I have a user interface that allows you to perform several deletions - right now it just calls this endpoint in a loop for each of the selected identifiers, which is not super efficient. I would like to be able to send an array of identifiers to the Delete method in this case ... how can this be achieved?

+4
source share
2 answers
 [HttpDelete] public HttpResponseMessage DeleteFolder(int[] ids) { // Do stuff } 

and then you can 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] 
+4
source
 [HttpDelete] public HttpResponseMessage Folder([FromUri] int[] ids) { //logic } 

api call

 DELETE /api/Folder?ids=1&ids=2 
+4
source

Source: https://habr.com/ru/post/1490174/


All Articles