April 2017
Intermediate to advanced
454 pages
12h 51m
English
When our application starts up, the created hook is engaged and will run the code with Axios. The first line performs a GET request to the API endpoint:
axios.get('http://api.adviceslip.com/advice')
This will return a promise. We can use the then method on any promise to act on the result if the promise resolves successfully:
.then(response => { this.advice = response.data.slip.advice })
The response object will contain some data about the result of our request. A possible response object is the following:
{ "data": { "slip": { "advice": "Repeat people's name when you meet them.", "slip_id": "132" } }, "status": 200, "statusText": "OK", "headers": { "content-type": "text/html; charset=UTF-8", "cache-control": ...Read now
Unlock full access