forked from estartandodevs-course/exercises-sync-async-cep
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 51bdd4f
Showing
4 changed files
with
2,155 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "exercises-sync-async-cep", | ||
"version": "1.0.0", | ||
"description": "Exercício de criar um programa que retorna o endereço completo pelo cep - Estartando Devs ", | ||
"main": "src/index.js", | ||
"scripts": { | ||
"test": "jest" | ||
}, | ||
"keywords": [], | ||
"author": "ED Team", | ||
"license": "ISC", | ||
"dependencies": { | ||
"jest": "^28.1.0" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
Para este exercício utilize o recurso de Async/Await do Javascript. | ||
Será necessário buscar as informações em uma api externa (ViaCep). | ||
Baixar o resultado, tratar o retorno. | ||
Documentação da API: https://viacep.com.br/ | ||
*/ | ||
|
||
const BASE_API_VIA_CEP = "https://viacep.com.br/ws/"; | ||
|
||
function getCep(cep) { | ||
return fetch(`${BASE_API_VIA_CEP}${cep}/json/`) | ||
.then((response) => response.json()) | ||
.then((response) => { | ||
if (response.erro) { | ||
throw new Error(response.erro); | ||
} | ||
return response; | ||
}); | ||
} |
Oops, something went wrong.