Created
May 6, 2019 13:43
-
-
Save omariosouto/cf026634106398fa8bc97126b04cbc35 to your computer and use it in GitHub Desktop.
This file contains 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
// Pegando dados | |
const xhr = new XMLHttpRequest(); | |
xhr.open('GET', 'http://twitelum-api.herokuapp.com/tweets') | |
xhr.send() // Disparando a requisição | |
xhr.addEventListener('load', function() { | |
console.log('Resposta do server', JSON.parse(xhr.response)) | |
}) | |
// Enviando dados | |
const novoTweet = { | |
conteudo: 'Tweet teste 2', | |
login: 'omariosouto' | |
} | |
const xhr = new XMLHttpRequest(); | |
xhr.open('POST', 'http://twitelum-api.herokuapp.com/tweets') | |
xhr.send(JSON.stringify(novoTweet)) | |
xhr.addEventListener('load', function() { | |
console.log('Resposta do server', JSON.parse(xhr.response)) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment