[MUSIC] Once we've created our video repo, we still have to worry about how we expose it to the mobile clients who are going to be sending HTTP requests to store videos and to do things with it. Now, it may seem fairly straightforward. We could just go and create a Controller, and let's say it's our video controller, or our video service. And inside of this controller we could go and have, the repository, that we had just created, automatically wired in by Spring. So, we don't actually even have to define it in our configuration. We can allow Spring, to go ahead and find it in one of its internal configurations and auto wire it in. So we have our VideoRepo, and then we'll just call this repo. Now, what we'd want to be able to do is allow clients to send videos to store. So the first method we might add would be public void save. And we take a video. [BLANK_AUDIO] And then inside of this thing, all we're going to do is say repo.save and the video. And we could return a response to the client if we wanted. And we'd probably want to go and just put a request mapping on this. To something like /video/save. And you can imagine that, and again we would need annotations on the parameters, like on the video to do the body of the request. We might want to return some type of different status codes depending on what happened. But the primary thing that we are going to have is methods over and over that look like save. And then we delegate to the repository. And we're probably going to have another method for delete, so that people can remove videos. [BLANK_AUDIO] And it'll take some data. And then we'll probably have another method for searching. So we might have a method that returns a list of videos. And we have some findBy, let's say name. And you can imagine that we're going to have lots and lots of methods where all of these methods in the controller are just providing a request mapping that essentially takes a video and then delegates to this video repository that we created, that actually has all the logic for storing this data in the database. But it's a lot of work to go and have to individually create each one of these methods. It's doing very little work. It's essentially just delegating to the repository. Wouldn't it be nice if Spring had a way of just automatically exposing our video repository as a service that could be accessed via HTTP. So clients could directly talk through Spring to this video repository. And we didn't have to write all of this code that's very repetitive and isn't really what we want. We'd really like to eliminate this stuff. And simplify, so that we can just write the things that matter, our logic that matters, and we can ask Spring to go and do repetitive boilerplate things that we have to do over and over, like save, delete, and find videos, and delegate to the video repository. Luckily, Spring provides a way to do that through something called Spring Data Rest. And the basic idea behind this is that we can take a repository and we can automatically expose it through a series of request mappings like /video or /video and a particular property. And we can send different HTTP request methods to take actions on those resources, because Spring provides a rest based mechanism through Spring Data Rest to interact with a video repository. So each of the pieces of data in the repository is considered a rest resource, and then the actions like get is essentially a retrieval of a resource. Put is the replacement of a resource. Post is the addition of a new ray, resource to the list of resources. Delete is the removal of a resource, and so Spring Data Rest gives us a way to do this. To use Spring Data Rest to make our repository videos accessible via HTTP, or to make any other repository of data accessible HTTP. We have to make two important but small changes. The first one is, on our repository interface, we need to add the @RepositoryRestResource annotation. And we're going to add two different attributes to this annotation. One of them is going to be the collectionResourceRelation. And we want something like videos, so if you have a collection of them how do you name it? And then we're going to have the path, which is going to be the path that we're assessing this stuff with. So, something like video would turn into the ability to access this stuff through a request to /video. So, the path is determining where this thing gets exposed. It's similar to how the request mapping is built. It's telling Spring where to expose this thing. Now this is the first thing we have to do and we add this this annotation to our repository interface. So, we call VideoRepo, and it extended a bunch of stuff. And all we have to do is go and add this one annotation to the actual repo, and the interface for it, and Spring will automatically know that this is something I need to expose. And here is where I need to expose it. And when I'm having multiple instances of the resource that I'm returning, here's what I'm going to call them. I'm going to call them videos. Now, the second thing we need to do is somewhere we're going to have a configuration. So, in some class we've got a configuration that we're using to define the components of our application. So we're just going to call this, app. We're going to assume it's in the Application, class. And we have this configuration that's defining all of these different components in our application. To enable Spring Data Rest, we need to import its configuration information to automatically set up its controller that its using internally to route and send requests to our repository. So in order to that, we need to import an additional configuration, and it's the RepositoryRestMVC Configuration. [BLANK_AUDIO] This is quite long, it's starting to extend past my writing capabilities on this board. But I think I just barely gotten it into the video, hopefully. So by adding this one annotation right here, importing the RepositoryRestMVC Configuration class. And adding this annotation to our repository interface, the RepositoryRestResource, we simply told Spring to go and automatically take our repository, and expose it using rest to mobile clients through HTTP, or through, to any other client, to a browser based client using HTTP. So we can now send, because we've designed the path to be video, we can send GET, we can send POST, and other requests to this URL in order to automatically go and add and remove and change the data that's within that repository. After we've created the repository interface for our video repository or any other repository to save and retrieve videos or other objects that we want to persist, the last thing that we have to do in order to enable those repositories, is tell Spring to automatically create the implementations of those repository interfaces. And the way that we do that is in our configuration for the application. So let's assume that we have a configuration on a class that we'll call Application, we'll assume it's in the core application class. And we have some various components that are being defined as beings or otherwise, in this configuration. The last thing that we need to do is add an annotation @enableJPARepositories. [BLANK_AUDIO] And this is the last key thing that we need in order to tell Spring to automatically go and create the implementation of our repositories. Spring needs to know that I need to go and create those implementations. Now, there's two way that it can discover the implementations. The easiest way is we can add @ComponentScan, and then some package, like org.mobile, let's say. .data. And let's assume that this is where our repository is. By telling Spring to go and do a component scan, Spring is automatically going to look at all of the classes in this Java package that we've specified. So we're just dispecifying fully qualified name of a Java package. And then Spring is going and automatically scanning that package and discovering all of the interfaces that extend to something like CrudRepository and the other different types of data repositories that we would have in Spring. And each time it finds one of those interfaces, it then automatically goes and creates an implementation of it. And then, anywhere where we want to use that particular repository, and we've added an, @AutoWired for, for example, the video repo. Spring will automatically, after having gone through this package, finding the video repo, seeing that it's a repository, it will create an implementation of the repository and then dynamically find all the places where that repository type is referred to with at @AutoWired, and then place that repo implementation object into all of those AutoWired variables or methods.