How to recover the tragos data in the api query in NODEJS

Asked

Viewed 241 times

0

Good morning Galera.

I am consuming an external api and am receiving the data as follows:

{
"place_id": "151508663",
"licence": "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright",
"osm_type": "way",
"osm_id": "348425570",
"lat": "-22.8799486",
"lon": "-43.1023092803839",
"display_name": "Colégio Nossa Sra das Mercês, Travessa Francisca Ribeiro, São Lourenço, Niterói, Microrregião Rio de Janeiro, Região Metropolitana do Rio de Janeiro, RJ, Região Sudeste, 24130-005, Brasil",
"address": {
    "school": "Colégio Nossa Sra das Mercês",
    "road": "Travessa Francisca Ribeiro",
    "suburb": "São Lourenço",
    "city": "Niterói",
    "county": "Microrregião Rio de Janeiro",
    "state_district": "Região Metropolitana do Rio de Janeiro",
    "state": "RJ",
    "postcode": "24130-005",
    "country": "Brasil",
    "country_code": "br"
},
"boundingbox": [
    "-22.8806171",
    "-22.8792948",
    "-43.1025817",
    "-43.1019949"
]

}

how can I access each item of this in Ode, I have tried so:

var id = [];
this.id = res.place_id;

More brings me Undefined

can help me?

  • Carlos, you can pass on how your request is being made?

  • 1

    Good afternoon my friend, I am following the example: https://www.thepolyglotdeveloper.com/2017/10/consume-remote-api-data-nodejs-application/

  • Carlos, I think the problem may be that it is an asynchronous request and its attribution is being made prior to the return of the API. Neste caso eu sugeriria a você utilizar o async/await (https://medium.com/@oieduardorabelo/padr%C3%B5es-de-design-com-async-await-em-node-js-fccfbe24572e) para buscar os dados ou então utilizar o axios (https://github.com/axios/axios) because he works with Premomise and his request would not be "behind"

  • I’ll try my friend thanks, but I bring the data if I’m not able to access them in the array

  • beauty! Anything gives a hehe touch.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.