Consume A REST API With Axios Client

Step 1: Install axios client
>npm install axios
Step 2: Import axios library
import axios from 'axios'
Step 3: And the get call the function as below
axios.get(apiUrl).then((repos) => {
console.log(repos.data);
});
GET Example
loadJSONaxios(){
axios.get("/android/menu_by_grade_json.php?grade=2").then((repos) => {
console.log(repos.data);
});
}
POST Example
let json={'name':'Jahid','email':'jahid@gmail.com','mobile':'01715785434'};
axios.post('http://domain/create.php',json)
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
Comments 0