Created
July 29, 2023 23:05
-
-
Save douglasabnovato/f997dea5a96334e4704ca4e91a0c1437 to your computer and use it in GitHub Desktop.
Para consumirmos uma API precisamos trabalhar com a assincronicidade, que nesse caso foi tratada com o async await. Em seguida, converter o retorno em JSON para objeto Javascript com o método .json(). Além de chamar a função para ela acontecer.
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
async function conectarComApi() { | |
const conectaApi = await fetch("https://api.thecatapi.com/v1/images/search"); | |
const conectaApiConvertido = await conectaApi.json() | |
console.log(conectaApiConvertido); | |
} | |
conectarComApi(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment