Install axios
npm install axios
Import axios
import axios from 'axios';
Use axios
axios
// Specify the methods, common ones are GET and POST
// The url of the endpoint
.get("https://insta.nextacademy.com/api/v1/users")
// When the request succeeds, do something with the response
.then(resp => {
// I like to console.log the resp to see what the data look like
// This way I know what I can do to manipulate and interact with the data
console.log("resp.data", resp.data);
// Do something else with the data
this.setState({
users: [...resp.data]
})
})
// When the request fails, do something with the error
.catch(err => {
console.log(err);
});