Skip to content

Instantly share code, notes, and snippets.

@doug2k1
Last active September 1, 2017 02:55
Show Gist options
  • Save doug2k1/9ddab480d04f5828edbc87c67b5937f5 to your computer and use it in GitHub Desktop.
Save doug2k1/9ddab480d04f5828edbc87c67b5937f5 to your computer and use it in GitHub Desktop.
// requisição:
// não é preciso informar o método (GET é o padrão),
// nem cabeçalho ou corpo (requisição GET não precisa de corpo)
fetch('https://api.github.com/repos/facebook/react/releases/latest') // URI
.then(response => {
// recebemos a resposta e logamos o status
console.log(response.status)
// retorna o corpo da resposta em formato JSON
return response.json()
})
.then(json => {
// loga o JSON
console.log(json)
})
// em caso de sucesso vai logar:
// 200
// { ... conteúdo do corpo da resposta em formato JSON ... }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment