httpdartdart-http

Difference between http and HttpClient in Dart


I'm trying to understand the difference between the http package and the HttpClient class in the dart:io library. My purpose is to known when I should use which. I see both of them used to apparently do the same thing.

I've seen these Q&As:

This is what I think is true so far but my understanding is fuzzy:

So to sum it up, I would say that each one can do anything that the other can as well, but it is easier to use the http package since this one is more high-level. Is that summary correct?


Solution

  • The http package is an abstraction over dart:io and dart:html.

    So if you want to share code between browser and other platforms that makes HTTP requests, then it's best to use the http package. Then the code will just work everywhere.

    If you don't care about the browser use what API you like best. In Flutter the http package just wraps dart:io's HttpClient.