S, Sven Van Caekenberghe piše: > On 01 Jul 2011, at 12:53, Janko Mivšek wrote: > >> Why not simply: >> >> (ZnServer startOn: 1337) >> onRequestRespond: [:request |: ZnResponse ok: 'Hello world'] >> >> >> This is the closest form to that node.js example and really show the >> power of Smalltalk and its closures. Also understandable to everyone >> including the (IMHO) majority, who don't understand design patterns like >> Delegate well.
> If you compare all the Zn delegates that are included, such as Nick's > ZnDispatcherDelegate, I think it is clear that #handleRequest: is a good > interface. Different use cases require delegate's with more or less features > and thus complexity. > > But for the sake of short/elegant examples, I added the > ZnSingleThreadedServer>>#onRequestRespond: convenience method, so the > examples now become: > > (ZnServer startDefaultOn: 1337) > onRequestRespond: [ :request | ZnResponse ok: (ZnEntity text: 'Hello > World!') ]. > > and > > (ZnServer startDefaultOn: 1337) > onRequestRespond: [ :request | ZnResponse ok: (ZnEntity with: request > contents) ]. I'd just introduce yet that ZnResponse ok: 'Hello world'. To cover the most common response body and this will be really easy to grasp for newcomers. Nothing specially to learn upfront, just that simple two lines with seamless way to respond with some text. This complicate a bit Zinc internals, but the gain on simplicity on API level is IMHO worth that. Janko
