1

I know how to do get and post request but im unsure on how to do delete request?

my json url and it's requirements:

String url = "http://35.186.145.243:8080/users";

{
"userId":"user1",
"price":"$1.300"
}

so i need to pass userId and price as parameters in order to delete the information from the api

  main() async {
    String url = "http://35.186.145.243:8080";

    Map map = {
      'user_id': "user1",
      'price': "$1.300",
    };

    print(await apiRequest(url, map));
  }

  Future<String> apiRequest(String url, Map jsonMap) async {
    HttpClient httpClient = new HttpClient();
    httpClient.open('delete', url, 0, '/users');
    httpClient.close();
    return 'Success';
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("API DELETE"),
      ),
      body:
          Center(
            child: RaisedButton(
              color: Colors.lightBlueAccent,
              child: Text("DELETE!"),
              onPressed: () => main(),
            ),
          ),
    );
  }
irongirl
  • 895
  • 7
  • 14
  • 31
  • Try the following [Link](https://stackoverflow.com/questions/22460194/how-can-delete-requests-be-made-with-a-dart-httpclient), if you have a problem don't forget to mension the problem, I cant really get the problem your facing from your question. – FoxyError Mar 05 '19 at 09:26

1 Answers1

0

Try removing port number from your URL and adding it to the port parameter in http open method.

String url = "http://35.186.145.243";

httpClient.open('delete', url, 8080, '/users');

Amsakanna
  • 12,254
  • 8
  • 46
  • 58