parent
8fcaa2cf56
commit
fd1ce4d741
@ -1,26 +1,21 @@ |
|||||||
class BugNotifier { |
class BugNotifier { |
||||||
notify (message) { |
notify (uri, message) { |
||||||
|
return postData(uri, message) |
||||||
postData('http://example.com/answer', {answer: 42}) |
|
||||||
.then(data => console.log(data)) // JSON from `response.json()` call
|
.then(data => console.log(data)) // JSON from `response.json()` call
|
||||||
.catch(error => console.error(error)) |
.catch(error => console.error(error)) |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
function postData(url, data) { |
function postData(uri, data) { |
||||||
// Default options are marked with *
|
|
||||||
return fetch(url, { |
return fetch(url, { |
||||||
body: JSON.stringify(data), // must match 'Content-Type' header
|
body: JSON.stringify(data), // must match 'Content-Type' header
|
||||||
cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
|
|
||||||
credentials: 'same-origin', // include, same-origin, *omit
|
credentials: 'same-origin', // include, same-origin, *omit
|
||||||
headers: { |
headers: { |
||||||
'user-agent': 'Mozilla/4.0 MDN Example', |
|
||||||
'content-type': 'application/json' |
'content-type': 'application/json' |
||||||
}, |
}, |
||||||
method: 'POST', // *GET, POST, PUT, DELETE, etc.
|
method: 'POST', // *GET, POST, PUT, DELETE, etc.
|
||||||
mode: 'cors', // no-cors, cors, *same-origin
|
mode: 'cors', // no-cors, cors, *same-origin
|
||||||
redirect: 'follow', // manual, *follow, error
|
|
||||||
referrer: 'no-referrer', // *client, no-referrer
|
|
||||||
}) |
}) |
||||||
.then(response => response.json()) // parses response to JSON
|
.then(response => response.json()) // parses response to JSON
|
||||||
} |
} |
Loading…
Reference in new issue