Add 'post JSON' example to readme (#173)

This commit is contained in:
Chris Veness 2016-10-08 21:35:19 +01:00 committed by Timothy Gu
parent 3c053ce327
commit f30cce86c4
1 changed files with 14 additions and 0 deletions

View File

@ -125,6 +125,20 @@ fetch('http://httpbin.org/post', { method: 'POST', body: stream })
console.log(json);
});
// post with JSON
var body = { a: 1 };
fetch('http://httpbin.org/post', {
method: 'POST',
body: JSON.stringify(body),
headers: { 'Content-Type': 'application/json' },
})
.then(function(res) {
return res.json();
}).then(function(json) {
console.log(json);
});
// post with form-data (detect multipart)
var FormData = require('form-data');