Skip to content

Instantly share code, notes, and snippets.

@doug2k1
Last active August 31, 2017 19:32
Show Gist options
  • Save doug2k1/ff9ec4dee7ac3ddae164b6d21a6c973e to your computer and use it in GitHub Desktop.
Save doug2k1/ff9ec4dee7ac3ddae164b6d21a6c973e to your computer and use it in GitHub Desktop.
// the request:
// POST a new email address to my GitHub account
fetch('https://api.github.com/user/emails', { // the URI
method: 'POST', // the method
body: JSON.stringify(["[email protected]"]) // the body
})
.then(response => {
// we received the response and print the status code
console.log(response.status)
// return response body as JSON
return response.json()
})
.then(json => {
// print the JSON
console.log(json)
})
// on success will log:
// 201
// { ... contents of the response body as JSON ... }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment