I have just (r6683) landed a change that will bread existing useof the HTTP server.The HttpServer class used to have a setter called onRequest toset the function that was called for all requests received. This setterhas been removed in favour of multiple handler registration.
I've just seen the commit and I'd like to ask the community: do you think this is the right approach and the HTTP server should be more high-level, or should it stay low-level, allowing different kinds of abstraction to be built on top of it?
This was added as a convenience that you don't have to use. It does
not really change the low-level nature of the basic API in my mind.
We are still thinking about the way we want these interfaces to look,
so thanks for starting a discussion of this. We do want to keep the
low-level APIs. However, we are also starting to add higher-level APIs
in various places to help users who do not need the full flexibility
of the low level. The handler registration seemed like something a lot
of users would probably want to do in any case and it made sense to
have support for that.
Cheers, -- Mads
I played around with Go on App Engine and Go's mini server is using the same handler based approach. I guess the "best solution" depends on the kind of apps you want to build predominantly. With Dart we speak of a new class of (GWT-like) apps where the client just fetches static app code and communicates with the backend over XHRs. There will be no "common page decoration handler" because the page decoration will be part of the same (static) app code that will be fetched via the same static content handler.
We are still thinking about the way we want these interfaces to look,
so thanks for starting a discussion of this. We do want to keep the
low-level APIs. However, we are also starting to add higher-level APIs
in various places to help users who do not need the full flexibility
of the low level.
I really hope you guys are looking at Node.js as THE platform to emulate, because it has been insanely popular for a reason.
I hope not :) because popular != well architectured.
Regarding previous comments of splitting the code into two classes I was considering doing that but having either a sub class or a wrapper class of the HttpServer called WebServer which would have the method addRequestHandler and setter defaultHandler. For this change I decided against it, but as things evolve we might reconsider. We are very focused on keeping things as simple as possible but still with a bias against supporting the most common use cases.
One of the reasons for introducing the interface RequestHandler was to make it easier to have libraries of request handlers. E.g. a FileRequestHandler class which can deal with all the details of serving files from disk. Providing these request handlers as classes instead of functions seemed to be the best solution. There are no immediate plans of extending the RequestHandler, but going forward having that option is convenient.
My main concern is just with the `Object handler` arguments. Since Dart doesn't support overloading, I think it's best to either only support one type of argument, or have two separate methods, one for each type.
Haven't closely followed the discussion, but would another alternative not be to make classes functions?
Imagine that every class that implements an 'apply' or 'call' method could be used as a function ...
(Somehow generalizing the 'runnable' concept).
Wow, proposal from january, how could I have missed that?
Sound really good!
> Wow, proposal from january, how could I have missed that?
> Sound really good!
AFAIK, this isn't a proposal anymore, it's already specified (albeit not implemented, but I hope this changes soon).
LT
Hi,So I've been playing around with sqljocky and was able to successfully query my MySQL database and have moved on to writing a simple HTTP server that displays the results. I was following the sample at http://www.dartlang.org/articles/io/#web-servers and of course it didn't work and it took me a while to find this discussion. So, I'm trying to get this working:
#import('dart:io');main() {var server = new HttpServer();server.listen('127.0.0.1', 26570);server.defaultRequestHandler = (HttpRequest request, HttpResponse response) {response.outputStream.write('Hello, world'.charCodes());response.outputStream.close();};}
using lynx as my client. The 'Hello, world' text is not displayed until I kill the dart app. What am I doing wrong? Any help is appreciated.
I just filed http://code.google.com/p/dart/issues/detail?id=2918 today, that might be the issue? lynx seems to use HTTP/1.0 and HttpServer isn't compliant.