Home > Blockchain >  Fetching an API with multiple params
Fetching an API with multiple params

Time:10-28

I have an URL and I am trying to pass multiple params into it and fetch it with each param in the same call to provide the data for each param. For example: param_1 has different data from param_2, and I am trying to fetch both datas in the same axios call.

const data_1 = "param_1";
const data_2 = "param_2";

const URL = 'http://google_services?gls_url=${data_1}'
const URL = 'http://google_services?gls_url=${data_2}'

useEffect(()=> {
 axios(URL).then(res => res.data);
},[])

CodePudding user response:

If you want to be able to insert data_1 and data_1 into the same url, I'd suggest to pass a different parameter that you call data, as a useState. Now you can set data to data_1 or data_2 according to when you need it.

CodePudding user response:

I don't exactly understand your question or what the problem is, but I suppose, this is what you are searching for:

const data_1 = "param_1";
const data_2 = "param_2";

const URL = 'http://google_services'

useEffect(()=> {
 axios
 .get(URL, {
  params: {
    gls_url: data_1,
    photo: "34433",
  }
  })
 .then(res => res.data);
},[])

But u don't know where you need data_2

  • Related