4 Calling an external API - Spring Boot Microservices Level 2

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
there is however one change that I want to make to the to the code and the change that I'm gonna make this to use something called movie DB to get the movie information all right so the movie IDs hard-coded like I told you everybody's going to get two movies right that they've rated and they're gonna get the same rating however the movie DB is gonna contain movie information for whatever movie ID that you pups in and I'm gonna use that to make an external call to an existing API and get moving information which is live movie information to show to our users right it's a good example of showing how you can make an external call and how there are points of failure that can be introduced into the system by making an external call more external calls the more interactions you have the more failures you have so having extra points of failure is handy because of the workshop that we're doing hey we're doing fault tolerance so it's good to know that good to have reasons why things could fail so what is movie DB movie DB is a site which is kind of like IMDB kinda sorta but it's something that you can you can register create an account and you can go to the API section over here and then here you have pretty good documentation with good examples tell you how to discover a movie you can make a request given a movie name and it's gonna give you that it's you can make a request with the movie ID it's gonna give you that now let me go to the profile here API and here you see when you create an account it's gonna give you an API key all right this API key is what's required for making these requests so this is the API key that you're gonna be using for making API requests and I'm gonna be using this API to have the movie info service make an actually I call and get an actual movie information all right so let's take a look at this sample API request it's a movie slash 550 all right and the he is a query parameter here you see you get movie information I can change the movie ID to something else okay that movie information all right so this is the API that's we gonna be using right we're gonna pass the movie ID to it get that movie information and return that back in the response and the response is gonna contain like you have a title overview which is just perfect for what we want right okay so now how am I gonna add this to our micro-service right how am I gonna be adding this well here's what I'm gonna do go to my movie in first service and if you look at the cord on the github repo this is actually already there alright so I have this section of the code Reston's let get for object this is the movie info API right this line is already there so I'm actually making a call to this API dog movie DB dard slash 3 / movie ID and I'm passing in the API key okay so I'm making that call and then once I make the call I'm gonna be getting the information movie summary I'm gonna do the title and to get overview which can corresponds to the properties that you saw there I think have it in the POJO there where I can get the the overview and the original title properties from this response and this is what I am going to be returning all right so this is not all that interesting the interesting part really is how I get the API key alright I'm getting the API key from a property in my property file so you see I have this value annotation annotated with API dot key this is how I get values configured values from the application of properties file ok so we look at my application of properties file here in the movie in for service application of properties this is the state of the code that I have checked in I have API key here so you can feel free to go create you know your own accounts in a diary here I'm gonna be adding mine and then [Music] I'm going to restart the movie info service and I'm going to show actual results in the response but just kind of fun isn't it it's it's it's a little boring to look at high quadrant values it's nice to look at some live values so we started the server and the Drude URL for localhost 8080 one is a narrow page because we don't have anything up there I'm going to go to catalog slash user ID user ID can be anything here I'm just hard coding the values like I said so these are the two movies that we are getting back from the movie db-api cool this is good stuff now the two movie IDs are coming from let's see here the reading data service so here is where I have hard-coded these two these two ratings right one hundred and two hundred and that's where it's getting the values so here's the full API architecture so far all right so we have three services again but then the movie info service is calling an external API the movie db-api alright a slight addition we added to the to the micro service but nothing big right nothing significant and really few micro services not a lot of interaction happening fairly simple stuff
Info
Channel: Java Brains
Views: 186,614
Rating: undefined out of 5
Keywords: microservices, spring boot, microservices tutorial, java microservices, spring boot microservices, spring cloud microservices, spring cloud, spring, java brains, java, brains, koushik, kothagal, kaushik, spring microservices, fault tolerance, resilience, circuit breaker, bulkhead, hystrix
Id: 7nKKD2rKpUk
Channel Id: undefined
Length: 5min 52sec (352 seconds)
Published: Wed Jul 10 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.