Skip to content

Instantly share code, notes, and snippets.

@doug2k1
Last active September 1, 2017 02:55
Show Gist options
  • Save doug2k1/30ff66d4a1e8a1e0b12d974964422448 to your computer and use it in GitHub Desktop.
Save doug2k1/30ff66d4a1e8a1e0b12d974964422448 to your computer and use it in GitHub Desktop.
// requisição:
// adicionar um novo endereço de e-mail à minha conta do GitHub
fetch('https://api.github.com/user/emails', { // URI
method: 'POST', // método
body: JSON.stringify(["[email protected]"]) // corpo
})
.then(response => {
// recebemos a resposta e logamos o status
console.log(response.status)
// retorna o corpo em formato JSON
return response.json()
})
.then(json => {
// loga o JSON
console.log(json)
})
// em caso de sucesso vai logar:
// 201
// { ... conteúdo do corpo da resposta como JSON ... }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment