All right.
Welcome back.
So in this video we're going to talk about making or starting an application an express application
that uses an API.
So we're going to use a different API.
We haven't really seen yet.
It contains movie data.
If you're familiar with familiar with IMT the Internet Movie Database this is a version of the data
contained in that API called the Open Movie Database.
Oh MTV.
So MTV doesn't actually provide an API that we could use.
So someone went through and basically created this API.
Oh MBB open movie database that's free and contains all the movie information off of I am D-B.
So we're going to make a simple app basically has two views and express app one will be a search form
and you can type in something like frozen or Harry Potter and then it will do a search on the API using
your search term and then show you results page with a list of 10 movies set up to 10 movies at least
that match your query.
It's going to be very simple as it mentioned.
We're not going to style it or anything.
This is really about just showing you how to get going with an API and it's basically what we've already
seen using that request module just like we did here but instead of making the request just in a in
a empty J S file you'll put it inside of an express app like in a route for example.
So let's start by making our basic express app going to make whip's make a new directory here and I'll
just call this movie search app CD into that NPM and it
sure that's our name version.
How do app.
J.S. everything else is fine.
OK then we'll do our NPM install dash dash save and we want express we want SJS and we want to use request
because we're going to be making a request just like that.
Let that finish up.
And while that's going let's talk about the way that this API is structured.
So if we take a look on the documentation that you are at by the way it's just oh MDVIP com.
We take a look at the documentation and scroll down you can see that there is a list of parameters that
we can use.
So there are two main ways we access this API by ID or title and by search.
So this will make sense once I show you some examples.
But the idea is that if you have a specific idea of a movie so every movie has an idea.
So if I have the idea for Harry Potter and the Sorcerer's Stone the film then I can get all sorts of
information about that one movie plot the rotten tomatoes data you know the year it's made the poster
image a bunch of stuff but I can also search.
So if I'm not sure of a title or if you know I just want to add search capability and I want to get
multiple results.
So to clarify this first one we talked about we'll give you one Russell only and a lot of detail.
A lot of detail and information for one result but if you want to search and get 10 results and I can
search for Harry Potter or Harry just Harry and get multiple results but I won't get a ton of information
so I'll show you how that works.
Let's start with search.
Notice that the parameter S is required.
So that's the only required thing.
And the description is that it's a movie title to search for.
Sure it's kind of confusing.
But if we just make a request I'll show you what you are Lwin need to go to.
So I'm going to just copy this URL.
Or put up a new tab.
And if you scroll up you can see send all data requests to OODB API dot com slash.
Question mark so we'll do that slash question mark and then we're going to do a search so to search
we need parameter as it's required and it should equal the movie title to search for.
So as equals and let's do star.
So we'll get Star Wars maybe Star Trek hit enter and that's it.
And we get Jason 10 results Star Wars Episode Four Star Wars Episode 5 6 Apollo blah.
Star Trek Star Trek Into Darkness.
So we get 10 results there.
So that is a search but we'll see what we can also do is then take one of these let's say the ID right
here going to copy it and if we go back to the documentation you can also retrieve information by ID
.
So as you can see here we either need to use I or t.
So I will search by an ID be id TIV a search by an exact title and it gives us 1 result.
So I'll get more information.
So let's do it by eye.
So we can open up another tab.
MTBE API.
Question mark I equals that I am D-B ID.
You can see I get more information.
So not just the title and the year but the rating the runtime the genre director all sorts of stuff
versus this search here.
So we're going to work with this search.
We're going to have an API we're going to have a form that user can enter a query like Star Wars or
Harry Potter or whatever California and then we're going to take whatever the user types into that form
and just put it right here.
And you are.
So as will equal California then we'll get this Jason back and then we'll parse it and then display
the results.
So the last thing I want to mention is some of these optional parameters some of these other things
that we can work with.
So here if we take a look at the BY id search the by id query we can also add in things like We want
plot to be short or full or we want rotten tomatoes data.
So let's try that.
Let's do this here.
Take a look at the plot here.
Now if I add in with an ampersand that's how query strings are constructed and plot equals full.
It's a little bit longer.
I don't know if it's really that noticeable but it goes down to here versus if it's short it ends right
here and Darth Vader.
Likewise I can also add in tomatoes equals true which will give me rotten tomatoes data.
So we get all this rotten tomatoes data here as well.
So that's kind of fun.
The key thing is that you can add in these parameters.
This one is mandatory.
And then other things but they all follow that key value pair like a normal query string that you've
seen before.
But the way that you know how to structure these calls is based off the documentation and I should have
mentioned this earlier.
They have a nice example here so you can do a search like if you want to figure out OK let's search
for byte title movie that has Harry Potter in the title came out in 2000 13 not enough.
Actually there was one we can figure off and do full.
And I want Jaison.
It gives you that you are ill that you could use.
And it gives us a sample result.
So you can play around with this and we can change it to SML and we get this X-amount hideous Actimel
I don't like ex-MIL at all.
So that's kind of nice to play around with it.
OK.
So let's send this video here.
And then in the next one will actually get back to constructing the application.