1
Talk personal, all right? I’m doing a role that will be responsible for validating the ZIP code informed by the user. Basically in the call of an API the user will send the ZIP code on body and I need to validate if this ZIP code is valid, I did the function below:
const axios = require('axios')
const obj = {
infos: {
addres: {
cep: '04052030',
street: 'Rua Orissanga',
city: 'São Paulo'
}
}
}
async function cepCheck (request) {
const data = await axios.get(`https://viacep.com.br/ws/${request.infos.addres.cep}/json/`)
if(request.infos.addres.street != data.data.logradouro) {
request.check = false
return request
}else if(request.infos.addres.city != data.data.localidade){
request.check = false
return request
} else {
request.check = true
return request
}
}
const teste = cepCheck(obj)
The Obj created is only for testing. In the scenario I described I need to know if the result of the check is false or true to return a answer to the user in the API, only then enter the problem, because it is a promise the return always comes as {pending} And I really don’t know how to get around that. For the API I am using express and in case it is necessary I send the API call code as well.
Related: How can I use javascript async/await?
– Icaro Martins