Hello!
A quick email to mention I just released ZappaJS 2.2.1; this version
mostly updates dependencies, tests, and uses a couple external
dependencies to lighten the code in the module.
More importantly I released ZappaJS 3.0.0 which includes support for
Promises in two ways:
- If your request handler returns a Promise and the Promise is rejected,
the rejection is passed down to `next`, propagating the error down the
middleware pipe instead of hiding it.
@get '/', ->
Promise.reject new Error 'Oops'
- If your request handler returns a Promise and the Promise is resolved
to a string, the string is passed down to `res.send` -- similarly to
what is done in plain ZappaJS.
@get '/', ->
Promise.resolve 'Hello world!'
These two changes have the potential to break backward-compatibility if
you are using Promises in existing code, therefor I bumped the major
version number to follow semantic versioning.
But Promises support in itself wasn't a sufficient reason to introduce
these changes, so for a long time I just didn't see the point. What really
motivated me is the following.
I added a new `@seem` method(*) in the root scope of ZappaJS, which allows
you to do:
@get '/user/:name', @seem ->
user = yield user_db.get @
params.name
group = yield group_db.get user.group
@json {user,group}
Yes, `user_db.get` and `group_db.get` are async operations returning
Promises, and yes, the return value of the `yield` is the value of the
(resolved) Promise. I think this is rather neat! You can compare with
the regular, sans-generators, version in the updated documentation:
http://zappajs.github.io/zappajs/docs/crashcourse#asynchronous-dancing
ZappaJS itself does not depend on generators, so you can keep using it
under plain Node.js. However if your version of Node.js / io.js allows
for generators, you might want to give this a try!
That's all folks, hope you're still enjoying the show, and thank you for
staying tuned and supporting ZappaJS ;)
Stéphane
(*) The name refers to the package by the same name[1], if there's a
strong sentiment for a different in the ZappaJS root scope I'll be
happy to add it. ;)
[1]
https://www.npmjs.com/package/seem
--
tel:
+33643482771
http://stephane.shimaore.net/