Skip to content

Instantly share code, notes, and snippets.

@raphaelpor
Created November 6, 2016 23:57
Show Gist options
  • Save raphaelpor/16f941db21cd6c12c91db3feed3c4c63 to your computer and use it in GitHub Desktop.
Save raphaelpor/16f941db21cd6c12c91db3feed3c4c63 to your computer and use it in GitHub Desktop.
fetch('file.json') // URL de destino.
.then(response => { // 'response' possui todas informações da resposta.
if(response.ok) { // Bool para checar a respota.
return response.json(); // É necessário transformar o 'body' para json, para que possa ser manipulado
}
})
.then(data => { // Recebe o 'data' em formato json.
console.log(data);
})
.catch(err => { // Recebe um objeto contendo as informações do erro.
console.log(err.message);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment