Skip to content

Instantly share code, notes, and snippets.

@omariosouto
Created May 6, 2019 13:43
Show Gist options
  • Save omariosouto/cf026634106398fa8bc97126b04cbc35 to your computer and use it in GitHub Desktop.
Save omariosouto/cf026634106398fa8bc97126b04cbc35 to your computer and use it in GitHub Desktop.
// 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