Difference between http and HttpClient in Dart
Asked Answered
A

1

22

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)
  • both http and HttpClient (with HttpClientRequest) can make GET and POST requests (source)
  • both http and HttpClient can be used on the client and the server

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?

Accentuate answered 27/2, 2019 at 18:6 Comment(0)
E
33

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.

Economics answered 27/2, 2019 at 18:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.