I created a environment-independent HTTP client, will the Dart team do this too at some point?

91 views
Skip to first unread message

Steven Roose

unread,
Dec 17, 2014, 6:05:10 PM12/17/14
to mi...@dartlang.org

Tiny rant on the Dart team: they created json_rpc_2, a library that provides an implementation of JSON-RPC v2. However, although JSON-RPC v2 works with both WebSockets as regular HTTP connection, json_rpc_2 is almost impossible to get working with regular HTTP. json_rpc_2 expects a Stream and a StreamSink for responses and requests.

So I wrote an Asynchronous HTTP library that provides these things. While doing so and really getting annoyed by the io/html duality when dealing with WebSockets and HTTP, I made id environment-independent.

And to my own surprise, it worked! (Using deferred loading of libraries.)

Look at the code example here: https://github.com/stevenroose/async_http
That code works in stand-alone VM, Dartium and with dart2js.

Now, my question: will the Dart team ever provide this functionality? Like a WebSocket or HttpClient class that works everywhere?

Bob Nystrom

unread,
Dec 18, 2014, 5:21:46 PM12/18/14
to General Dart Discussion, Natalie Weizenbaum
On Wed, Dec 17, 2014 at 3:05 PM, Steven Roose <steve...@gmail.com> wrote:
Tiny rant on the Dart team: they created json_rpc_2, a library that provides an implementation of JSON-RPC v2. However, although JSON-RPC v2 works with both WebSockets as regular HTTP connection, json_rpc_2 is almost impossible to get working with regular HTTP. json_rpc_2 expects a Stream and a StreamSink for responses and requests.

Improving the usability here is something we'd definitely like to do. It's been a while since I looked at that code, but if you have ideas on how to make it easier to use over vanilla HTTP, please do file a bug or talk to Natalie about it. It lives here: https://github.com/dart-lang/json_rpc_2
 

So I wrote an Asynchronous HTTP library that provides these things. While doing so and really getting annoyed by the io/html duality when dealing with WebSockets and HTTP, I made id environment-independent.

And to my own surprise, it worked! (Using deferred loading of libraries.)

Yes! We've known deferred libraries can kinda sorta be used for cross-platform code for a while. The limitations are:
  1. It forces you to have an async API. That's a huge usability cost for some libraries. (For example, we wouldn't want the path package to be async!)
  2. It affects the shape of your dart2js output. An application that depends on your package may not to defer that part of your library.
So, my opinion has been that this isn't a viable general-purpose solution to cross platform code.

Now, my question: will the Dart team ever provide this functionality? Like a WebSocket or HttpClient class that works everywhere?

What I really hope we do is provide a general-purpose way for users to write cross-platform code—be able to provide a platform-independent API backed by more than one platform-specific implementation and have Dart choose the correct one. Some of us on the team have been trying to make progress on that for a long time and haven't succeeded yet. I hope we do at some point, but so far I haven't seen a proposal for a language change that I like.

Cheers,

- bob


Natalie Weizenbaum

unread,
Dec 18, 2014, 7:47:02 PM12/18/14
to General Dart Discussion
I'm puzzled why you didn't just use the existing http package for this. It's asynchronous, and works seamless across the browser and the server. It doesn't natively support a notion of a stream of requests and responses (since these being disconnected is not the usual mode of using HTTP), but it's easy enough to create.

On Wed, Dec 17, 2014 at 3:05 PM, Steven Roose <steve...@gmail.com> wrote:

--
For other discussions, see https://groups.google.com/a/dartlang.org/
 
For HOWTO questions, visit http://stackoverflow.com/tags/dart
 
To file a bug report or feature request, go to http://www.dartbug.com/new

To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.

Reply all
Reply to author
Forward
0 new messages