#100DaysOfWeb in Python Transcripts
Chapter: Days 93-96: Vue.js - JavaScript user interfaces
Lecture: Concept: Calling API with axios
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
We saw on our application that to do anything interesting we needed to interact with our remote service. Yeah, we're able to copy some fake data
0:08
but that's not the real app, right? So we needed to call the API. And here's the function that we wrote to get that data
0:15
and convert it back into the movies that we wanted. Turns out to be super simple because we use this thing called Axios.
0:22
With Axios, we can just call the get function and give it a URL, and that returns a JavaScript promise. We can do a then for a success call
0:28
and a catch for an error call. So over here we, in our then we just grab the response, get the data and on the data we wanted the sub-element
0:38
that was returned from the service called Hits. That's a list, so we just muster away so we just say that.movies equals response that dated a hit.
0:45
One other little caveat here notice that we're actually capturing the this value before we call the get and then we're using it
0:53
I'm calling that that variable gettin in here because the this pointer is not the same in the call-back as it is on my start.
1:00
So if we want to get access to things like the movies property of our view app we've got to capture it before the call.