// post with stream from resumer var resumer = require('resumer'); var stream = resumer().queue('a=1').end(); fetch('http://httpbin.org/post', { method: 'POST', body: stream }) .then(function(res) { return res.json(); }).then(function(json) { console.log(json); });
// post 表单数据
var FormData = require('form-data'); var form = new FormData(); form.append('a', 1); fetch('http://httpbin.org/post', { method: 'POST', body: form }) .then(function(res) { return res.json(); }).then(function(json) { console.log(json); });
// post 表单数据并且修改header var FormData = require('form-data'); var form = new FormData(); form.append('a', 1); fetch('http://httpbin.org/post', { method: 'POST', body: form, headers: form.getHeaders() }) .then(function(res) { return res.json(); }).then(function(json) { console.log(json); });
// node 0.12+, yield with co var co = require('co'); co(function *() { var res = yield fetch('https://api.github.com/users/github'); var json = yield res.json(); console.log(res); });