I am trying to consume an api in js via get by Xios

Asked

Viewed 340 times

1

I’m trying to consume an API on js via get by axios, API containing a parameter apikey, how the code should look?

as I’m trying to do:

axios.get('url', {params{apikey:'chave_api_key'}})
.then(function(resposta){
console.log(resposta)
})

1 answer

1

According to the API of Axios, you must pass a configuration object as the second argument, containing the property params with the parameters you wish to pass.

Thus remaining:

axios.get('/user', {
  params: {
    apiKey: 'YOUR_API_KEY'
  }
})
  .then((data) => {
    // Do stuff.
  })
  .catch(() => alert('Houve um erro!');

Browser other questions tagged

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