Last active
September 1, 2017 02:55
-
-
Save doug2k1/30ff66d4a1e8a1e0b12d974964422448 to your computer and use it in GitHub Desktop.
Exemplo de requisição HTTP Post em JavaScript - https://medium.com/douglas-matoso-brasil/b%C3%A1sico-de-http-para-desenvolvedores-frontend-954fa3688c87
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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