node.js - Promise-based node http framework? -
node frameworks work via (err, result)
callbacks.
is there promise-based http framework node, healthy community , in active development (such express)?
on http client side, there new fetch api
https://fetch.spec.whatwg.org/
fetch()
allows make network requests similar xmlhttprequest (xhr), main difference [it] uses promises, enables simpler , cleaner api, avoiding callback hell , having remember complex api of xmlhttprequest
(https://developers.google.com/web/updates/2015/03/introduction-to-fetch)
some implementations:
- browser "poly-fill" (older browsers) https://github.com/github/fetch
- node version https://www.npmjs.com/package/node-fetch
- cross platform version https://github.com/matthew-andrews/isomorphic-fetch (i don't word "isomorphic" used in situation... anyway)
here example code:
fetch('/some/url', {method: 'get'}) .then(function(response) { // rejoice \o/ }) .catch(function(err) { // error :-( });
Comments
Post a Comment