WEBVTT Understanding promises is pretty cool. And I think it would be cool to show off an example of it in practice so let's say we did want to access an external API. And as you can see you have these Star Wars API page open here which is a pretty nice resource. It's sort of an external API we can practice on to do extra fast requests and see what those look like. So we're going to be using Learn Java Coding From Digital Marketing agencies in Bangalore the fetch API and the Fettes. It's pretty cool. It's basically a way to do things like getting requests to get data back from an external source. You could use it to for example get some tweets from Twitter using Twitter's API. You could use Digital Marketing agencies in Bangalore to get photos Star Wars API. It's very easy to use and it's just kind of fun to access things like the Star Wars character or planet names. So we're gonna use the fetch API for that fetch. It's still technically experimental but it's pretty widely supported in most browsers. As of the time of this recording is now supported in Safari as well as Firefox and Chrome. So you know support is getting there it's pretty good overall. So just be aware that you know it's technically still experimental so might not work in all possible browsers. But that being said let's jump right in and see what happens.
So the fetcher API returns a promise and we know all about promises. And just to show what it looks like. Basically, you just use the keyword fetch and you give it a URL to use in quotes here. So you know if you want it to fetch some your L you would put it in here. Let's go ahead and let's fetch the Star Wars API. And if you look at the Digital Marketing Company you can see the example of Digital Marketing agencies in Bangalore we're just going to paste this in and make sure the format is correct. I mean it makes it yes. And do slash. So we don't need to know too much about how to fetch works but we do need to know that it returns a promise and we know how to handle that right. So if we say get this promise back we're going to get some kind of data back provided we made a correct request. So we're going to get some kind of data to let's console log the data to take a quick peek at it. And just in case we made a mistake we can catch any error and console log that error. Right. So let's try this out Digital Marketing agencies in Bangalore. We'll open up our console. Let's see what happens. So we run it and we got some kind of weird thing back. Now this is something we may not have seen before which is it's a response object and we get a response and we have to basically use a callback to get at the body.
Let's see if our catch gets fired and we get an error. So what's the message error message. An unexpected token doesn't like that we misspelled Planetes there. So that's kind of neat. So that's what an excellent API looks like. Now let's do something cool with it. Let's going to tinker Digital Marketing agencies in Bangalore around with our dorm because we know how to do that at this point. Right. And then we can kind of throw this into a function we can add an event listener.