HttpClient vs http pub package

814 views
Skip to first unread message

James Wendel

unread,
Dec 14, 2012, 4:35:52 PM12/14/12
to mi...@dartlang.org
I was looking at doing Http request from a dartvm and noticed that there are 2 http client libraries out there right now.  There is the official one that is part of DartIO and another "http" pub package that looks to be pushed by a couple google devs.


I haven't dug too deep into either yet, but I'm guessing the HttpClient would be the way to go?  Would there be any advantage to use the "http" pub package over HttpClient?

I see the "http" pub package uses Futures to handle the callbacks (instead of passing in a callback function like HttpClient seems to do).  Is there an advantage to this, or is it just a style difference?

Nathan Weizenbaum

unread,
Dec 14, 2012, 6:03:29 PM12/14/12
to General Dart Discussion
The dart:io HttpClient is lower-level and supports more esoteric corners of the HTTP API than the http package. The http package intends to expose a higher-level API (such as using Futures instead of callbacks). It has built-in handling of higher-level concepts like form encoding (both application/x-www-form-urlencoded and multipart/form-data) and has more convenience methods for common cases like sending and receiving requests/responses as strings.

The http library is designed to be composable, which means that you can relatively easy add layers. Pub uses this to add a layer for oauth2 authentication. You can also use this to swap in a mock client for testing purposes.


--
Consider asking HOWTO questions at Stack Overflow: http://stackoverflow.com/tags/dart
 
 

Søren Gjesse

unread,
Dec 17, 2012, 3:18:33 AM12/17/12
to General Dart Discussion
The Dart libraries are currently being refactored, and changes will start to land on bleeding edge soon. This will include an update of the dart:io libraries (including HttpClient), where most uses of callbacks will be changed to use futures and/or streams (for some initial information on streams see http://news.dartlang.org/2012/11/introducing-new-streams-api.html).

You can see the current state of the library refactoring on the experimental/lib_v2 branch (http://code.google.com/p/dart/source/browse/#svn%2Fexperimental%2Flib_v2).

Regards,
Søren

Matthew Butler

unread,
Dec 17, 2012, 10:56:45 AM12/17/12
to mi...@dartlang.org
+1000 to this. I'm excited to see streams land in bleeding_edge. 

James Wendel

unread,
Dec 17, 2012, 11:17:30 AM12/17/12
to mi...@dartlang.org
It looks like the Dart:io package on bleeding edge has TlsSocket as well, woot!  I'm starting a project where I'll need http connections to a webserver over SSL, so I may have to try out bleeding edge.

Also, thanks for the heads up that HttpClient will be changing to use Futures.

Søren Gjesse

unread,
Dec 18, 2012, 2:53:29 AM12/18/12
to General Dart Discussion
The SSL support will also be in M2 which is being prepared in http://code.google.com/p/dart/source/browse/#svn%2Ftrunk.

Regards,
Søren


On Mon, Dec 17, 2012 at 5:17 PM, James Wendel <jmwe...@gmail.com> wrote:
It looks like the Dart:io package on bleeding edge has TlsSocket as well, woot!  I'm starting a project where I'll need http connections to a webserver over SSL, so I may have to try out bleeding edge.

Also, thanks for the heads up that HttpClient will be changing to use Futures.

--
Reply all
Reply to author
Forward
0 new messages