All right.
Welcome back.
So we talked about what API is our what it is what the term stands for.
We talk to some examples.
Next we're going to talk about how they work and not just you know how they're structured but what they
send back and what the data looks like.
So what this giant mess was here and and why is that better than HMO.
Before we do that I have this little graphic here of you know a human interface to iTunes.
You can see you know the iTunes browser.
But then here is what you get from the iTunes API.
So this is you know a much cleaner much more simplified.
And this is you know a nice cleaned up version that's color coded but it actually really looks like
this.
But it's pure data that we get.
So it's still you know album names and you are extra images and dates and ratings and prices but rather
than this format.
And as you can see here I'm actually searching for Beyonce.
And then these are the results you see here.
What I'm doing is writing an API call that will do the same thing search for Beyonce music videos.
So this is how the API is structured.
You this is changes from every API you have to read the documentation which is what I did here.
But if you make a request to this you Arel which I'll do right now.
And we look at what is the response it's going to be hard to read because it's just a chunk of text
.
But this is the underlying information about Looks like 50 Beyonce music videos.
So I could use this if I wanted to build a Beyonce music video viewer application or Beyonce music video
shuffle app that would just pick one and play it randomly.
OK.
So again the key here is that this what you're seeing here is a representation of you know a computer
interface a code interface.
So here are some other end points which is the term for these you or else of the iTunes API or one of
the iTunes API is the search API.
So you can search for Beatles songs and this is what you would do.
And tity song term equals Beatles can search for podcasts about code Harry Potter movies.
And this is just to show you that you know this is how the iTunes API is set up.
It's not a pattern that you would follow for other API.
Again you just figure it out using the air using the documentation for the particular API you're interested
in.
OK so what is this stuff that we see here.
There are two main formats that API of web API is responded with nowadays.
We're used to him owl.
That's what everything we've done so far.
Response with the you know the app this Web site I'm looking at now here is written and edged him out
.
My browser takes it displays it for me nicely but there's a lot of extra stuff in there.
We talked about we don't need we don't want when we're asking for data from an API.
We don't want that structure of the page.
The color that we just want the content that underlies it all.
So these two formats that are most commonly used are called SML and Jaison so SML will start with that
stands for extended markup language or extensible marketplace bridge.
It's very similar to h tim L and the syntax is you can see here we have these angle brackets opening
and closing tags that slash.
Where it's different though is that it doesn't describe presentation or structure of of the presentation
.
We're not saying that this is bold and this is a list item.
All that it does is code key value pairs so data as you can see here this is a person tag and instead
of a person there's an age that's 21 a name which is Traveston city which is Los Angeles.
So key value pairs you can nest things inside of each other and there's no real rules on what you can
put here.
So it's not like edged him out when those particular tags you put whatever tags you want and this is
one way of encoding data.
And then our code would get this back and it would be able to understand.
OK this is a person and has an agent name and a city and city is Los Angeles.
Jason is another way of storing data and sending that data back without any of the pretty Chimo or ugly
depending on who you are.
But none of that extra stuff and stands for javascript object notation.
And if you're familiar with javascript objects what you should be this will look very familiar.
So this is the exact same data we had here.
A person who is age 21 name is Travis.
City is L.A. using Jaison.
So we have an object where we have person which is another object where we have age or just 21 name
is Traviss city is Los Angeles so it's just another way of storing data.
Either one works.
There are other options as well.
Ex-MIL used to be used a lot more than Jason Jason though is quickly become much more popular and the
main reason for that is that a lot of times we're making API calls.
We're using javascript.
So when we get this data back in it looks like this and we're in javascript so I have a javascript application
and I'm asking for weather data and it comes back as Jason.
Well then I can very quickly use it in my javascript I don't have to convert it from this format into
a javascript object.
I can read it from this which is basically Javascript.
And very quickly or it's very quick.
One thing though to note you do need quotes around the Keys so it's not exactly javascript do need quotes
around the Keys but it's very very similar.
And again I have a comparison here if you want it just you know look at them side by side same data
represented differently.
So Yahoo has a weather API that we're not going to use right now but I'm showing it to you the documentation
for it at least because it allows you to toggle between Jason and Zemo.
So what we have here are a few example requests requests.
So if I wanted to figure out how to ask for the sunset time and Hawai it will show you first down here
this is where you need to make a request.
So this long URL looks kind of crazy but this is where you would need to request and you need to write
.
Let's see.
Select astronomy sunset from weather forward.
So this giant thing you don't need to worry about it too much but there is this one part format equals
Jaison and the one you make this request which we can do on our browser.
This is what you get back in.
So it looks like sunset and Hawai is at 6 or 5 p.m. so I can do that.
I can also just request that and I get that response right here.
So it's just a regular request but I can also switch to SML and you'll see the exact same information
.
It's just looks a little different and how it's formatted but the same information is here some said
is 6:55 p.m. It's a little clunkier to use SML.
Some of the older API is only support Exham but most new things support Jaison is pretty rare nowadays
to find a new thing a new API that only supports X-amount.
So we're going to focus on Jason but I want to hammer the point home that they are just both formats
.
Given this situation where we have let's say you know yahud weather has data and it wants to get it
to us well it's not going to send it as a demo.
But there needs to be a predictable format for it to send it in so that we can kind of Dakota and unwrap
it and you know get meaning from it.
SML is one option but Jason is a much easier option.
It's shorter usually a lot less text where we don't have to write these closing tags but it also just
works really nicely with javascript which is what we're doing most of the time.
So with all of that said if we go back here this is Jason just to refresh your memory.
This is the underlying API that Jaison API for readed in particular for our Shlash Ah adorable photos
.
This is the underlying J song.
And it's kind of a mess to look at.
There is a chrome plugin or a chrome extension or like to use called Jason view or on.
You were just on view.
It's a chrome extension.
It makes Jason look like this where you can kind of explore easier.
So I'm going install it here.
And then when I go back and I make that same request it takes a moment.
So you can see I see the original and then the nice formatted version from the extension and it's a
lot easier to see the information.
And there's still a lot here but I can see the structure now how things are related.
You can see that it's Jason.
So we have the curly braces.
See if I can make this a bit bigger.
We have the key value pairs.
We have you know array brackets strings numbers.
All this stuff in here.
And what's nice is that I can close things down expand them and explore the data rather than that giant
mass that you could see here.
It's the same code it's just formatted nicely.
So I highly recommend installing something like that.
They make them for Firefox and pretty much every other browser out there.
I highly recommend it.
You can also just look for some viewer online.
If you don't want to install an extension you can go to a site like this and paste in your Jason and
then click on format no format it for you.
So I could select all of this go here format and it does that as well.
But it's not as interactive.
I can't collapse it and expand it.
So to wrap up Jason is one of the formats X-amount Jaison to most common for API is for web API has
to respond with rather than HTML all that kinkiness.
So what we'll be doing is writing applications that will make a request for this information and we'll
get it back S.J. song.
We won't be using this redit information but another japes on API will get that information back in
or app will be able to use it very quickly and then do something with it save it to a database do some
analysis on it and then show something to our user eventually as Kimmo.
So you see how to do that in the next video