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:
http
is high level and HttpClient
is low level (source)http
can make post requests but HttpClient
can't (source)http
and HttpClient
(with HttpClientRequest
) can make GET and POST requests (source)http
and HttpClient
can be used on the client and the serverSo 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?
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
.