Add 'post JSON' example to readme (#173)
This commit is contained in:
parent
3c053ce327
commit
f30cce86c4
14
README.md
14
README.md
|
@ -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');
|
||||
|
|
Loading…
Reference in New Issue