I have the HTTP call in php code:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $urlForTheCallGoesHere);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$data = curl_exec($ch);
curl_close($ch);
Which I now need to convert it to convert to VueJS Axios call. What I know so far, is that a Axious calls can be created as:
axios.get(urlForTheCallGoesHere)
.then(res => {
console.log(responseData)
//do something with the responseData
})
.catch(errorData => {
console.log(errorData)
//do something with the errorData
})
}
I'm aware that custom params to the call can be added like this (an example):
axios.post(exampleUrlForSomeRegistrationLink, {
email: "exampleEmail@gmail.com",
password: "examplePassword"
}).then(res => {
console.log(responseData)
//do something with the responseData
}).catch(errorData => {
console.log(errorData)
//do something with the errorData
})
And also I'm aware that requests/responses can be manipulated (for example in main.js entry file) with assigning a default values or with interceptors:
//using default values
axios.defaults.baseURL = 'http://changeTheUrlForTheCallExample.com';
axios.defaults.headers.common['Authorization'] = 'exampleValue';
axios.defaults.headers.get['Accepts'] = 'application/json';
//using interceptors
const reqInterceptor = axios.interceptors.request.use(config => {
console.log('Request Interceptor', config)
return config
})
const resInterceptor = axios.interceptors.response.use(res => {
console.log('Response Interceptor', res)
return res
})
But with all of the above, I am still not sure how to convert the php code to VueJS code (using Axios). The main problem is how to add the values for the options CURLOPT_RETURNTRANSFER, CURLOPT_FOLLOWLOCATION and CURLOPT_SSL_VERIFYPEER as above?