#17 RESTful Web Services | Spring Rest | Spring Boot Example

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
now when you open s tears it will ask you for the workplace you want you want to work with again you can create a new you can clear a new workspace odd you can work with the same workspace which will be which we were using for eclipse ultimately springiest years or s3 as itself is Eclipse right now you can verify that when you go to sto tiny silicon have or HDL you will get an option you will get that this works on Eclipse platform specifically Eclipse neon 3 so the version which I am working on maybe if you are using a new version it will be having a registration of neon or maybe Eclipse ok so if you remember this will be project which we have worked earlier right now since I have this project in Eclipse I have worked on this project in the existing workspace I got this project here now what I will do is I will create a new project so to create a new project now this time we are going for spring project ok there's an option of spring boot in spring it's a new thing again you can go with normal spring MVC or you can go with spring boot now just to make this thing easy for you I'm going for spring boots because spring boot says you don't have to do much of the configuration in fact if you're going for spring MVC there are lots of competitions which you have to take care Springwood says hey don't worry you can judge I can start with the project and the way you can do that is by saying new so I click on your project Explorer and say new and create oh ok so I'm not getting to the option here so I was right like I would say oh can you see that I'm not getting the option of spring project here so if I if I see I don't have a spring budget option we are using HDS right so we have to make sure that you are using a spring perspective so if I click on here you can see we have a spring perspective you have to click on that and say ok now you are in spring perspective now if you right click and if you say new and if you click on spring startup logic now you can see we are getting option of spring startup project now this is basically your spring boot project so if I click on spring starter project um okay it will give you the service you'll again we talked about this in a some in some time here I would mention live less I will mention my project name as spring boot left because this is not just a rest a project this is a springboard flash project and we'll mention the group group ID with say Condor telescope and we'll mention zero condor telescope okay everything is set let's click on next now here we have to select where because we are working with websites to the select web and nothing else just click on next and then click on finish the moment you do that you can see we got a project now this is a spring boots logic and you can also see s there s simply means a spring project and at the end you have boot this is a string boot project if I expand this and if I go to my form Dalek mph Alex let's see what exactly this file is if I go to form the recommend five you can see we have we have spring boot dependency here and then we have spring boot start up start up web so this is the web project basically this is the thing boot web project you can also implement MVC here where we are going for spring list let's close this and I think else if I expand this mean if I expand Java counterexample if I open this thing boot rich app you can see we have a main method here and you can if you run this code it this will this will work now one of the awesome thing about spring boot project is when you collect web and if you expand your memory dependencies of course you will be getting to some web libraries there but with those web libraries as you can see we have spring in we have spring MVC here with this we have one important thing which is this one can you see that we have an optional tom can't embedded now what exactly it means let's say if you build a project on your machine and you your machine in your in your machine you have eclipse you have Tomcat installed everything is set up let's say if you're going to your friend's house or if you have a different machine now if you run this project on on the other machine what you do is you have to install it uncle as well you have to download Tomcat you have to configure Tomcat but spring would say hey don't worry why you have why we need a external Tomcat but I can give you embedded target that simply means you don't need a external server what I will do is I will stop the external server you can delete it delete this if you want other simply stop this now what I want is I want to create a ok I want to create a URL using which I can access some data now we have a choice of creating a web page here from which you can access data but that's not a good thing right we are building a restful web service where you don't have to mention a page we can request the data using postman so whatever you do is I will first of all on this code and of course this will not work this will work maybe let's try so it's a run as son as oh now how do you run this do we have to run this on server no this is offspring boot project right so anyway you want to run a spring boot project you have to select bring boot app just click on this now that's your spring boot app which is running and you can see in the console here it is running let me just minimize all this Express stuff which we never use anywhere and we got an error it says if the port is already busy oh that's bad is it the issue yeah that's the issue because I wanted to have my Eclipse running and running straight here let me close my Eclipse and let me just make sure that this is this which stops oh maybe I will delete this tomcat server from here to be unsafe sighs anyway so I was I think again I will say is run as run a spring boot app which should work now and you can see Oh again we got an error what's wrong who is using the port number 80 80 that's bad really bad ok so what I will do is this will not be an issue in your machine ok what do I do here is I will change my port number in case if you are facing the same issue you can change your port number you can just go to applications or property file and you can say it's our dot quote again my intention here is not to teach you what is what is the Springwood and how to configure this stuff or you can learn that in a different cause of string projects right but if you want to change your port number that's very easy to screw to efficient properties and you can change your port number to eight zero eight one now let's run this this should work now otherwise I will call this project Alice there is one as one as spring boot apps it's running Oh finally it is started I don't know what which service is using maybe the eclipse is not software properly closed maybe this one is not too up on the close so but this is working you can see we are using a port number which is 80 81 okay now what I will do is I will go to my postman I will say hey I want to request for 80 81 and it will say enter you got nothing of course we will not get in you will get nothing like but what I want is I want to fetch all the aliens so let's say I get request I will say I want to fetch all the ages if I send or send it if I click on the send request it should return the data ok now how do I do that it's very easy we just have to create a class and that class is responsible to return the data the way we have done in rest or spring of these Jersey right I will mention this is my alien controller not technically this should not be a controller this should be a resource that makes more sense like this is a resource I click on enter now how do you mention that this is a spring project I mean how do you mention that this is a spring a controller order I souls now to do that we have we just have to use and annotation which is called as rest controller so anyway you want to implement virtual API you just have to annotate it with rest controller the way we have done in in Jersey we have used ad path we have to use at rest controller here and this we just have to mention a method so we say method name is public or this return a list of aliens again we can buy database code but that will duel after some time we say list of alien and that was it obviously this is get alien and this will return a list now to return at least we have to get at least first right so other critter list of aliens here I was the least or alien and I will name this as alien sequel to new alien but the problem is we don't have a Aiden class here that means first you have to create disease in class oh now I am bit lately I will ensure creating the class I was just simply copy business again you can call it as code real right the same alien class lets me paste it here now problem solved is it 2000 salt yeah brother solve it we do not have an issue with aliens now and I will simply return the aliens but unfortunately this agency is empty so I will say alien I will say alien a 1 equals your new alien and I will insert some data for this I will say a 1 dot set ID will mention the idea is 1 0 1 I would say a 1 dot set name I will set the name as marine and I will say a 1 dot set points I will set the points as 70 okay that's my point let me just use one word object I would say copy this and create one one one object for me this will be a - a - a - a - and this will 1 0 - I will name this as Priya let's say point is Eddie once I got these two objects two alien objects let me add that in a in that least I will say aliens dot add let's add a 1 I would say aliens dot and let's add a two okay so we have added this to object everything should work now now okay so before before running this code let's let I have this question for you will this work I think about it and let's see the answer now so let's restart the application now there is one thing you have to or you have to remember when you work with filling boot don't start your project once again if you don't this project once again it might give you an issue because spring boy project has embedded target so it will not restart when you're on this project you have to click on restart to restart the project or they start the tomcat server let's go back to our postman and say hey postman send oh it's still not working of course it will not work because we forgot one of the annotation here which will map it right it remove the past annotation then here we have to use request mapping because we are mapping both requests right so we have to say it was mapping and I will say request mapping with slash aliens or we don't even need slanter so is the alien so whenever you get a request for alien this is what you have to run let's just start the application and let's go back to over tomcat or sorry postman and let's say is one it worked can you see that we got different data we got you r101 the first aliens because the second alien as well it's so simple right so instead of using Josie we can also use springboard now the thing which you have observed here we have added no dependency nothing right in fact we got the data in a dozen format and does not something what Jason we don't have to actually add any dependency everything is there but who is doing that in in your J in your Jersey we have Jersey converters white which is moxie here if you expand this Navin dependencies you can see we have something called a Jackson now Jackson is pre-built in in spring rest project or spring WebLogic so this Jackson is just judging Jackson is responsible to convert your Leafs of objects into Jace's right so it's an exciting tool to work with I get into indie-pop second tutorial we talk about how do you use post request put request and any requests so I hope you are enjoying it don't click on like button if you're enjoying it and do subscribe for the video thanks for watching
Info
Channel: Telusko
Views: 160,625
Rating: undefined out of 5
Keywords: telusko, navin, reddy, tutorial, java, rest, restful, webservices, webservice, spring, boot, webapp, example, project, restcontroller, requestmapping
Id: zjhWPRXfGJ0
Channel Id: undefined
Length: 12min 25sec (745 seconds)
Published: Tue Jul 25 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.