Languages

React - fetch data using axios GET request with api key parameter (as variable)

0 points
Asked by:
Majid-Hajibaba
972

How can I fetch data from API using axios GET request with api key from a variable?

I want to fetch data from NASA API using unique api_key generated on their website, but I'm not sure how to pass it as apiKey variable inside GET request.

Right now I am passing it inside url like this and it works:

My code:

1 answer
0 points
Answered by:
Admin Dirask Community
4380

You can pass an object as a second argument of axios GET request, which contains object with params property:

In your case it would be:

 

See also

0 commentsAdd comment
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join