基于Promise的节点http框架?

sle*_*ica 17 http node.js promise

节点框架通常通过(err, result)回调工作.

是否存在基于承诺的Node框架,具有健康的社区和积极的开发(如快递)?

wir*_*res 13

在HTTP客户端,有新的fetch API https://fetch.spec.whatwg.org/

fetch() 允许你创建类似于XMLHttpRequest(XHR)的网络请求,主要的区别是[它]使用Promises,它可以实现更简单,更清晰的API,避免回调地狱,并且必须记住XMLHttpRequest的复杂API

(https://developers.google.com/web/updates/2015/03/introduction-to-fetch)

一些实现:

这里有一些示例代码:

fetch('/some/url', {method: 'get'})
  .then(function(response) {
    // rejoice \o/
  })
  .catch(function(err) {
    // error :-(
  });
Run Code Online (Sandbox Code Playgroud)

  • 为什么这会被投票?这怎么回答这个问题呢?这是一个Node和承诺的HTTP客户端,但也许我错过了一些东西...... (2认同)
  • 问题是关于服务器端 (2认同)

wir*_*res 6

https://github.com/mzabriskie/axios

基于Promise的HTTP客户端,用于浏览器和node.js

示例代码:

// Make a request for a user with a given ID
axios.get('/user?ID=12345')
  .then(function (response) {
    console.log(response);
  })
  .catch(function (response) {
    console.log(response);
  });
Run Code Online (Sandbox Code Playgroud)


Stu*_*t K 3

您可能对Q Promise 库的作者 Kris Kowal 编写的Joey感兴趣。社区并不大,但 Kris 经常在 freenode 上的 #montage irc 频道上提供帮助。