[MUSIC] To start this next example, it's helpful to look back at the previous video service controller so that we can understand some of the inefficiencies in the code that we created. In particular, if you look at the video service controller from the video controller with JPA example, if we open this controller up, one of the things that we'll rapidly see is that we've created this video repository that is dynamically provided by spraying an at auto wired into our controller, and then most of our controller methods are essentially just delegating to the repository. So when somebody wants to add a video, we're simply calling videos.save and then returning. When somebody wants to get the list of videos, we're simply getting the list of videos and returning it to them from videos.findall. When somebody wants to find a particular video by name, we're simply delegating to the repository and asking it to do the work. So it seems like there should be a way to eliminate all of this delegation. Why should we provide all of these mappings? Shouldn't there be a way that Spring can automatically figure out how to provide all of these services through a web and a restful interface without us creating a separate controller and providing separate methods that are essentially going and providing all of the right annotations to delegate to simple methods on the repository. Well, luckily there is. As we discussed, Spring data rest can automatically take a repository and expose it and it's various methods through a restful interface. So it can automatically create a controller that will expose a video repository and all of the methods on it like save, or find by name or delete through a restful interface that can receive HTTP requests, so we don't even actually have to go and create a controller that can delegate to it. We can, if we want to, but we don't have to, if we don't want to. So the way that we do this is, we've taken our initial video repository and we've added an annotation to it @RepositoryRestResource, and we've provided a path to it which if we go and look at the path, we'll see that that path is /video. So what we're telling Spring to do is take this repository and expose it as a service, a rest service that can be invoked via HTTP. So if we go and look at all of the methods like save and find a particular object or findAll and get a list of all of them, what Spring is going to do is automatically create paths, request paths that if an HTTP request is sent to them, will invoke those various methods. So in this case, if you want to get a list of all the videos, you can just send a get request to /video and Spring data rest will automatically invoke the repository's find all method, and return all of the videos. Similarly, if you send a post request to /video, Spring data rest will automatically take the body of that request, turn it into a video, call the save method on the repository, and then return an appropriate response to the client. So by adding this simple annotation, we've told Spring to go and automatically expose our repository using a restful interface and create all of the infrastructure to allow it to receive HTTP requests. Similarly if we go and look back at our application, we'll see that there's essentially nothing new here. All we're doing is creating an application, and again, we're not providing an implementation of the repository. All we're doing is telling Spring that we want to go and start up. Now what's interesting is if you see in the last version, we had a magnum.mobilecloud.video.controller package that had our video service in it, that provided all of these delegate methods. In this version of the application, we can actually completely eliminate the video service controller because we can simply add this single annotation to our repository, and suddenly, it will go and expose this entire repository through rest and allow clients to send HTTP requests. So we're actually getting more functionality than we had before because not only do we have the simple methods to add and list, but we also get methods to delete, to search them by all kinds of different mechanisms that we didn't have before, and we're not even having to write a video service controller at all. So not only have we taken our code and eliminated an entire class, we've eliminated complexity from our code because we don't have to write an implementation of a controller, we've also go in more functionality of it and we know that it's dynamically connected to our database and guarantees that it will save things correctly based on what we want. So this simple annotation is providing a significant amount of power to us to take a simple repository interface that we defined, and automatically create all of the infrastructure to allow us to save videos, and delete them, and to store them in a database and to make all of that accessible via HTTP. So yet again, this is an example where some simple annotations allow us to connect HTTP requests to complex infrastructure that Spring automatically generates for us. The other interesting new annotation that we'll add is we want to be able to have methods to find by name and find by duration. In this case, we've actually added a find by duration less than method, when Spring is going to provide an implementation of that we'll find all videos with a duration less than what we provide. But one thing we need to do is tell it how to map the parameters from an HTTP request to these particular repository methods. So the way that we do that is we add these app param annotations and what this annotation says is go and look at the title parameter which is the title parameter in either the query string, or however it's sent to the server, extract it, and provide it as the title that we're searching for in this find by name method. Similarly, we're saying, go and get the duration parameter out of the request in this case marked by @param, and provide it for the duration that we're going and searching by in the database. So again, the more that we leverage the features of Spring, the simpler our code becomes, the easier it is for us to guarantee that our code is correct because Spring goes and generates correct implementations of all of these complex functions that we need