Member-only story

React basic 6 — Use Axios Library to Fetch Data

Takuma Kakehi
3 min readMay 24, 2020

--

Axios is a library that makes it easy to send asynchronous HTTP requests to REST endpoints, and we will use this library to get some image data from Unsplash API as instructed in the Udemy course.

Unsplash is a shared stock photograph website contributed by numbers of photographers throughout the world. From their documentation page, you can learn how their API works and key information you will need to send the first Get request, such as your access key (you will need to create your developer account and app on their website in order to obtain an access key).

Step 1. Install axios to your React app

Simply type npm install -- save axios command to your terminal.

Step 2. Import axios to your app and call a Get request

Import axios and type axios.get() method with required arguments. There are two arguments: the first argument is an address which you will send a request to; and the second argument is an object where you can customize your request.

In this link, you will see a documentation for Unsplash search photo API. For the basis, you will need an address (/search/photos) and your query term. As previously mentioned, you will need an access key for the access authorization…

--

--

Takuma Kakehi
Takuma Kakehi

Written by Takuma Kakehi

An experienced product owner and interaction designer with a decade of versatile industry experience. Portfolio: www.ta-kuma.com

No responses yet