0

I am trying to delete multiple users from server by sending list of user ids but in http delete method doesn't allowed that.so if i want to delete users with ids 1 ,2 and 3 how can i do that in flutter. here is the code:

Map<String, String> requestHeaders = {
      'Content-Type': 'application/x-www-form-urlencoded',
      'Accept': 'application/json',
      'Authorization': 'Bearer $token'
    }; //bearer is important
    final ids=[];
    ids.add(1);
    ids.add(1);
    var response = await delete(
       Constants.BasicURL + Constants.Users+ids ,
       headers: requestHeaders,
    );
Addow
  • 104
  • 1
  • 2
  • 7

1 Answers1

0

Constants.Users+ids won't help. If your delete method accepts comma separated values then you'll need to conver your array/list into a single string with comma separated values as below :

Step 1 :

List ids = ['1', '2', '4'];

String idString = ids.join(',');

Step 2 :

api/deleteusers?ids=$s
Sukhi
  • 13,261
  • 7
  • 36
  • 53
  • comma separated string is not acceptable at server ,server side team needs just list of ids. – Addow Apr 22 '20 at 12:25
  • Okay. Can you give me a sample url ? See, list or array is something internal to Dart/Php/.net etc. When you send the data as a URl param, the URL is nothing but a long string. Check if [this](https://stackoverflow.com/questions/21863326/delete-multiple-records-using-rest) answer helps w.r.t. HTTP delete. – Sukhi Apr 22 '20 at 12:37
  • **static const String BasicURL="http://192.168.1.113:2003/v1/";** **static const String Users="users/";** these are my urls – Addow Apr 22 '20 at 13:42
  • So, the url takes parameters as, for example, ___/v1/users/1 (single param) or as ___/v1/users/1,2,3 (multiple). It could be comma-separated or dash or semicolon etc. Either way, you will have to create a one string derived from the array/list. – Sukhi Apr 22 '20 at 14:15