Spring Boot Course | Building REST API with Spring Boot + H2 Database

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello all welcome back to our channel yes it's been a while since i've uploaded a video and uh today we have come up with a new video so this video we are going to build a rest api not any ordinary as to api but we're going to build a production grade production ready uh production level api rest api using a spring boot right so if you spring uh if you're someone who is uh has less slight idea of spring boot or if you're interested to understand what spring is or spring boot is and this is a perfect video to start with right and uh often we don't hear about spray boot while we're in college or uh while we are you know trying to build up projects or not but when you enter a corporate world right spring is very big thing right spring is something which uh you know which makes or breaks a production and i have seen a multiple uh you know billion dollar projects being built using spring right so there are multiple advantages of spring and uh this is not the video to know to understand uh why spring is best and all so there are multiple videos that you can check out this video is uh solely no idea of this video is we are going to build the rest api so we are going to build a sample risk api and we will see how spring makes it easy or spring makes it uh uh quick or efficient enough such that the spring is being used in uh many production level uh projects right so this is the idea of this video and let's start with the product let's not waste any time so uh for uh building the spring i'm going to use the spring initializer so this is where i get my initial template of the project you can you can simply open your ide and you can create a project from there but by using spring initializer you can add dependencies easily right so we can also do it from directly from pom.xml in our project but we have to know take one more step and go and find this uh artifact ids around but the spring insulator is a good way to start right so i'm going to uh use maven as my project builder and maven project and java and i'm going to keep 2.4.5 as a springboard version and here you where you have to give your project so i'm going to call it as um yeah search yes and i'm going to call it as an uh crud api so we're going to create an api which is capable of performing all the code operations right and we're going to name it as a cloud api and so yeah rest api project right and uh java so i have a java 16 sdk so i will be using java 16. you can go with any version as possible as long as you have that sdk with you and here is where the interesting part comes in so uh here you can add dependencies right so uh what i mean by adding dependencies if we add our dependencies this template will know fetch those uh artifacts and dependencies and add it into our xml file so later when our maven is trying to build the project it will know go and find those ids and we'll fetch the projects into a local repository right so for this we need uh so the project we are going to build is a uh rest api right so when i say rest api uh there are three things right so we have a end user and we have a database right and api stands in between and we'll take the request uh no process it on our database used by the request so we need a database like for this video i'm going to use h2 database s2 database is similar to let's say if you have used android right so android has something called a sql database which is an inbuilt database you don't need to know install any drivers and all so this is inbuilt database which is a it's a small footprint but it can handle some terabytes of data right we're going to use h2 database we're going to use the spring jpa that is useful for all the db operations and uh so it's a lot lot important and it says the best right and we're going to use again swim web for all the mvc purposes so let's add that so i'm going to use the spring web for you know building rights restful images etc so we have a tomcat server built in for us so we can simply build the project and that server everything will be run for us we don't need to know go and install tomcat or service and everything will be streamlined for us by using string web and as i've said we're also going to use h2 database yeah so it is a sql database and it is in memory database so one thing to understand is that h2 is an in-memory database you are not going to use any external database but it is very simple to add external databases as well so once i have let's say now a project is being used run using http database right and it's just a matter of you know modifying one property file so that it can be uh later used to uh databases like post basic equality with mongodb or any kind of databases spring is very flexible and it works with almost any kind of database you think you can able to think it so you can perform it right so so this is the database and one thing is we need jpa so yeah so this is uh how we interact with the database right so if i have to know explain it in a very common terms this is where this is like an entire library of uh sql and how the data is being uh like uh the how database being managed and how we perform the operations will be provided by spring data jpa so these are the two dependencies that we need and uh you can say jar as a packaging manager and yeah that's it and i can simply generate this project and this will generate a bare bones file for us so let's go to documents and let's say yeah crud api so yeah we have that and let me just unzip it and uh we'll open that in our favorite id let's extract all yep it's been extracted right so the id that i'm going to use here is called as intellij ide right so i'm i have ultimate license so i'm using that so you can use any id like eclipse id or eclipse uh spring pcs or sts there is an id which is a sole purpose it is designed for spring itself so there are multiple ideas which you can use for the same purpose but i suggest intellij id and there is a community edition which you can download for free and there is also a licensed version ultimate edition if you can pay for the license you can go for it or there are other ways like uh student licenses anything like that uh even if you couldn't find a license for you you can simply go with an um free trial of 30 days right so that third day will be more than enough to understand how things work let's go to our documents and so yeah this is our project so this is a project i'm going to open this project trust it yeah so mine is a pretty weak system so it might take a couple of seconds to lower the entire uh dependencies right so i will i'm going to skip the video till that point and we'll meet you once we have okay uh the project has been set up and this is our project so you can see there are there is two file folder sites so this is a project folder and there is something called external libraries so external libraries is where the libraries that we have added the dependencies that we have added are being loaded from the internet right so we have a 16 jdk java jdk and these are all the dependencies that maven has bought us from the internet so it has no bought us a spring boot starter it has waters the spring boot jpa everything it is being bought by the maven itself right so these are all the external libraries these are being loaded into our youtube store and once you look at the project so uh there are one main file that you have to always take care of so this will have all the information of a project so like what's a group id artifact id version and so what's the java version what are the dependencies that you are using you can see that we have added a h2 dependency and we have added a spring boot dependency that is starter for web etc so these are this is how uh the dependencies are being brought into our project right you can manually add as many repositories as you can based on your need of the project right and the next thing that we need is uh yeah this thing so this is our package so our code goes into this package so nothing new to say right so let's open our first so this is the first template that we are given right so let's understand what uh how what is this like so it is uh importing springboard application and you can see we have no they don't at springboot application so this means that uh maven knows that uh this is a springboard application so we are saying that this is a springboard application so if without that it would be a pure old javascript sorry pure java right so but once we have added this springboard application we are denoting that this is our starting part of our application and when i run this so a project starts right and we can create anything here so so let's try and begin our rest api slowly right so so the rest api that i was thinking for this project is uh a jokes api sorry let's do a quotes api so let's say there's a we are creating an database of all the inspirational quotes from all the different authors like like uh mahatma gandhi uh mandela anyway any anybody you know these days no even people on instagram are promoting their codes right so let's do that let's create a database of all these codes and their authors and we're going to provide an api so api will give us all the codes and when we can perform all the thread operations like we can create quotes into the database we can update the codes we can retrieve the codes you can uh delete them and all the all this good stuff right so let's do that so uh in boot uh when we are trying to know build a rest api so there are few things to keep in mind so one is controller so controller is place where all the requests are being mapped and all right and uh we also need a model so model or a table so is like uh what is the table that you're creating right so for the jokes we are going to create some kind of a class right so for which represents a pretty particular quote sorry if i misplace jokes and quotes uh understand that i'm saying code and there's also something called as a repository repository is like how we are accessing our database and there is also company called a service right so these are all different layers so we separate our business logic from one thing to another so we try to loosely couple our data our code everything like that so this is the beauty of spring and when you know when you so simply some people talk about spring they only say that yeah spring is used for dependency injection right so that was true like 20 years back sorry not 20 years back maybe 10 years back right but now spring can do much more than only dependency injection right so let's try and build that so i'm going to create a package here i like to do this because i like to keep everything into packages so let's call it as quotes package quotes package keep it simple so so this package will keep everything that is every all the code related to our package so as i've said there are multiple things to build so let's build them and let's talk about them so first of all i need a model right so i'm going to call it as code and it's going to be a java class and also i need a controller right class code controller right and i also need a repository right so code repository and i also need a service right so code service let's keep it as an interface and let's also implement our service here so new class to your code service implementation right so let's say these are things that we need so we'll add anything if we need uh as we go on so code is a place where we create our code object so what are the things that we need in our code right so let's say uh so if i have a code then i need it to be it has a id right so make sense private long id right so each code has a unique id for that and also for uh each code has a what is code exactly so string code all right simple so what is the code is actually i think long sorry i generally forget these things okay uh we have a string of code and also we can say string of who is the author of that code right string author i think we should use naming convention properly id quote author and we also need uh let's say when it has been published right published published on or something like that oh straight sorry okay so it's going to be a string public sorry it's going to be a date right date let's do alt into that so yeah so these are our fields that our code will have so when somebody asks for our code so these are the code that we are going to store in the database so this is going to add table right so let's also say that it is going to a table right so this is going to be my table right and i also have to add it as entity so by adding an jpl will recognize that this is our table so we can see that uh the symbol has been changed right so uh apart from that we need to add our get resistance editors right generate and get resensitives uh select all yep so we got data status for everything and you also need two string also right to string yeah yep and we also need a constructor so up probably let's do generate itself so why take so constructive select all true so this is how we can generate a thing right but we haven't finished yet so we have this right so but how are we going to generate our id's right so id is not going to be generated by ourselves right so id is going to be generated by uh but it is going to be auto generated so auto generated i think there is something press generated so yeah so it is already generated and i think we have to method element type dot method okay wait uh so rest everything are going to be a columns so let's say this column and this is also going to be a column and even this is going to be a column but it is going to be uh auto filled right so we are not going to uh not push the date each and every time but we are going to say when we are going to create it right so that there is where the data is to be created so created timestamp right so yeah so this is how there are multiple annotations that this they provide for us so we can use them to do that so we can also provide names for columns i think yeah name is equal to and i'll call it as a quote and name i'm going to write an author so when we are performing a request from our client side this is this can be used for the bodies converted yeah so this is how you can know create a model for us so this model will be recognized as a table by our uh gpa right and so we have our id right so we have to specify that this is going to be our id in our table so i think yeah so id so this is what here so i have created a and i have created a no uh table you can call it as a table right so a table called as a quote so we are going to use uh uh annotation called as entity right so this is this will take care of that and so we have an id that is id so we're specifying that this is our primary key and this id is going to be generated automatically by our jp right so this is going to be automatically generated so as soon as we get new entries so each will get an id and so quote is a column and author is a column and published one is a call i'm saying that published on uh will be no automatically populated by the creation timestamp so whenever the request has been made so it will take the timestamp of that time and we'll add it to the order so and we have simply made our uh what you say or get a sensators and our override methods like tostring and our constructor so this is how we can do our model and once we have a model so it is a good place to go to control and understand what a controller is right so a controller is a place where all the requests that are being passed are being controlled since we called as a controller so in order to know uh know to make it possible so we are going to say this as a risk controller so we're going to enter it as a rest controller so now spring knows that uh this is a risk controller and this is where the mapping happens right and i'm going to you know map this uh to a path in my api so let's say uh mapping let's get to the mapping right let's uh it is called as request mapping so yeah request mapping and we can pass some kind of string here so i will say uh api so whenever somebody goes to slash api like so this is where uh this is where the code or this is where the controller takes him to right so now let's simply create a hello message for now then we can go ahead and create all our repositories and all so let's say public sorry public string and let's call it as hello it's basically hello and instead of string let's pass it as a list of strings this is going to be a list of string and it is going to simply return a list let's say list list dot off okay list dot off of let's say simply hello and what right so this is going to be a simple small api path so let's try and deploy this sorry i mean try and run this and let's see what's happening and how uh the browser or postman client reacts to that and you will also see some kind of uh errors and some some some settings that you have to perform so let's try and wait for white while this is the project has been built some kind of depreciating errors so that's not an issue for now the bill should start yeah the build has been started as you can see right so it is no it has initializing a tomcat server everything is being done there and you can see that tom has has been started on port 8080 right now if i go to a postman client yep if i go to a postman client and let's say if i say api slash let's go don't say let's say localhost api slash hello if i send that i'm going to get uh not found why is that yeah because we haven't specified the path right so when we are trying to perform again we have to also do get mapping get mapping and i'm going to call it as slash hello right and apart that since we're trying to use the jpa right so we have to also perform some settings here so when we go to application properties initially now the properties are nothing right but i'm going to show you one thing right so let me open this file here so these are few settings that you have to work since we're trying to use uh jpa uh and we're going to you are going to use h2 as our database uh we have to add these uh so let me explain what so this is this booth are solid explanatory so we are enabling h2 console and we are also setting its path to slash h2 and this sixth line it says that uh show sequel right so uh previously when we ran right so we we saw some console output right so if i enable this as a true this will show me what's happening in the back end so what are the sql commands that are being performed because i have created a model and i have name it as entity right so but in the back end the gpa will create a table so for that they're going to use subsequent commands these are going to be shown in the command prompt and this this is the important thing so ddl auto so there are multiple so in fact let me show this so this is sorry i think that was another uh so in staggered flow there is a beautiful uh article that was written by some person so regarding that so these are uh so basically we use this you know to say to our thing right so what happens when i restart this right so currently we are trying to testing the project so we haven't built the project but try to see the product so what happens when i try when i make a changes and try to restart the project so if i say create and drop so it's going to know drop everything right so drop all the previous uh no um tables and all and create a new schema for us so that is why we use create drop now let's save this and now if i build this you can see the console output is going to be a little different you can see the actual sql curve like create create our code right so let's see that right so spring boot has started right so yeah as you can see right so as i've said uh we can see the uh commands so which have been performed by hibernate so you can see that uh drop table if exits right so it is dropping all the tables that are being present previously dragging our sequences now it is going to create a new sequence and it is going to create a table for us so it is vnt double quote with id and with your uh varchar with date and it's it's also using primary case or id so this is how uh the table has been created in the backend and it is started a server on tomcat so we can go to our uh this thing and say localhost 8080 or even let's simply go to our this thing postpone and uh if i make a request now we can see that the output is hello world right so which we have passed in our controller right so i think you have an idea about controllers and how uh springboot know handles this uh mappings and all so this is a good time to know go to that some advanced topics right so you know this so now what we want is we want to perform know what uh crude operations right so for that first we need so we have a table that has been created but we have to know make a connection with the table your site so we are able to create a service and repositories for that so let's go to the repository and let me just make it as uh interface and interface is going to extend jpa repository right and it is going to take two arguments one is our model so our model here is a quote and our id is going to be long right so law so this is what uh replace long with the java.log yeah so yeah so this is what we are going to do so we are going to create our repository for that so we are simply going to know creator interface called as code repository which is going to extend jps deposit and we pass quote and long in that so long is saying that okay the idea are longs and code is our model right so now we have this and now it's that time where we create our services so quote service is where we know try and know this interface we define all the services that we want to provide like no uh we want to create a quote right so let's say uh it's going to return me a quote and i'm going to say create code right and it is going to take a quote and quote right so when the user makes a request in an aqueous body he sends a code so we are going to create a code for that and we are going to create a quote and we are also going to know find a retrieve code right so code i am going to say retrieve all quotes right so in that case i don't think we need any um we need any arguments for that so we're going to return all the codes and we can also return the code by id right so particular id so retrieve right retrieve quote by id so here in this case we are going to take long and id so we're going to take an id here so let's take this job along okay so and we can simply delete a quote void delete a quote and again you can simply pass long and id and uh create retrieve delete and update so we can also do that so quote update a quote right so now to update a code we already need actual code right so code quote and so when somebody sends a put request with a code in their body so we're going to update that we don't need that i think this is uh enough for us so these are we are performing all the operations right crude operations so i think that's it and i think we also need id for that so long long id because we we are not aware of the id right so i'm going to take the an id and do the code right so these are the services that you are going to provide to the user so now uh let's try and know uh do the implementation for that before that uh i think i made some mistake here so retrieval codes will return as multiple code sites so this is a good practice to keep it as a list list of multiple codes list output right so this is how we're going to do so now we'll go into our service implementation so here we are going to implement our code service code service and let's also override the functions implement methods yep so these are the methods that we're going to implement here and let's call it as a service so yeah now this will become a service here and this is service animation will say that we'll say no spring boot that it is the service and we're also going to pick there's a transaction because it's a response for the transaction so it's going to be a transaction right so now we have our code service and here we are going to implement our method so we are going to create a code right so for creating code we need access to a data database and we perform that right so for that we are going to take the private uh the republic of our code so code repository let's call it as code repository and it is going to be auto wired by uh right so it's going to be whatever by the spring and let's do that so in order to create a code so where uh we're given a code body so we can simply say quote repository dot save and pass code right so this is how this is how simple it is right so we have code repository and the code repository provides us with the multiple uh with multiple uh default functions for that so this is this is why we extended uh code repository with the jpi repository right and uh retrieve all codes so we are going to redo list of quotes right so for that i'm going to say quote repository dot find all and simply say that's it right so it's going to return everything but yeah that's it so it is going to return us all and these are going to be a list of them right so let's again confirm what is the return type of find all find out yeah it is going to be a list of quotes thanks so this is how everything works out and we have to retrieve code by id so for that case i'm going to say quote depository dot find find all by id right and we are going to pass our id here so id that's how simple it is and okay okay let's uh i think there's some wrong thing wrong here let's do this course repository dot find let's see okay find my id long id okay it is going to be create an optional optional is nothing but so in java optional is nothing but so let's say when you're trying to find something then it is not present right so if you are using option as a type right if it is found it then it's about written quote if it does not form it's going to determine that so this is what the best thing that i can use i can say id and i think i have to modify uh this as well so okay i think i have to modify this to optional yeah so this is going to be more fit option and even here in the service as it's going to be a marker as optional right so it is it can either written null when the particular quote is not present in the repository or if it is present then it is going to return me that okay and let's also try and delete this tweet okay okay how can we do that okay let's say return okay uh http dot okay yeah http status dot okay so we are going to return status as okay okay it's going to written http status that is if it is deleted it is going to return okay if not it is not going to do anything because we haven't found the tweet right so we're going to find it right so let's say flag code flag and let's say is equal to sorry is equal to uh quote repository dot find by id and you're going to pass id right so this is going to ask me to modify this to optional i will do that and now i want to see if if flag is present so if it is present then we know that there is a tweet that is present in that so in that case we are going to delete it from the repository okay uh quote repository dot delete uh deleted by id and our id is id true so else we're not going to delete it so uh the the best thing to do is uh create a custom exceptions for each of these things but we're not going to cover that in this video that will be up to over the head for that so public code update code so this is one thing that we have to take care of so how we are going to update a quote so we are going to be given id and a quote again we have to do the same thing so we have to you know check whether the quote is found or not so so yeah we found the code so once we found the quote what are we going to do so we're going to create a new new code there is a new flag and this is going to be of type quote and port new flag is equal to flag dot get right so we're getting it from this and once we got that so we are going to assign everything to our new flag so new flag dot uh set id okay let's say that id let me disable duplicate this okay we're going to set ids and what are the things so set author and set code and i don't think we have we can set time right so time will be automatically set that id is going to be what our present code dot id so present port is nothing but uh which is being sent by our user right get id so okay same thing code dot get author okay quote dot get code right so this is going to be a new uh new flag and they're going to know set this new flag into our this thing so since the id is already present so this will be like updating so now port repository dot save and we're going to save what new flag and while we are there simply return this so that uh the user will know what is the what is the change that he has made sorry quote repository okay so this is going to be update update and delete optional of retrieve okay so implementation is practically done i'm not sure if we are getting we are going to get errors or not but let's try and do this so let's try and map this so let me just copy this a bunch of times okay so what is the first thing that we need so api slash quotes i'm saying yes because it will return everything so when somebody goes to this thing we are going to written a list of quotes so yeah list of code and let me let me call it as it all ports so whenever somebody goes to slash quotes mapping we're going to say get all quotes and we're going to return list of i don't think we need a list of so because we have previously now made it as a list right so if i go back to our service implementation and what is that retrieval code so we are simply returning find all so what would the return type of this okay it is it is returning in the form of a list right so so we don't need to convert them so yeah let's go back to our controller and here we need to get a reference of our service right so let's say private uh code service implementation i'm going to call this code service implementation again this is going to be auto wide auto white right so now we can use this to perform all the jobs right so quote implementation dot get so retrieval codes that's it that's as simple as that so this is where i love spring food right so our repository our service our business code everything is you know uh so structured that you know this is just a matter of time right so we know we are simply getting that code implementation which has been auto wired so this is what a dependency induction is right so and again so one is quotes and what if a person wants to a particular course so this is going to be a get mapping this is also going to be get mapping and code and he wants a particular id right so he sends a particular id and he wants i want uh quote slash eight so he wants a quote with id eight right in that case we are not going to return list rv rb i think we can do that so we can say list stop for code okay and we're going to say list of let's call it let's say get a code by id it code it doesn't matter right so let's put id let's call it this by id so when we are trying to get by id so let's see the what is the method that we have sent so code service implementation dot what is that okay record by id and send in the id and so it so how can we get this parameter let me just check with my notes here okay so for getting the path variables right so for getting particular there is something called as a path variable right and if i say it path variable long and id so that is going to be no passed into this so once we have id here so we can simply say id right so what is that error list of quotes in convertible types cannot cast okay uh let it be so i'm going to simply pass code and remove this once again problem with this optional should i make it as optional okay why is that why is it optional because let's go to the implementation and okay okay we are trying to find it by id but we haven't checked whether it is present or not right so if it is not present then it is going to return this null okay no problem that will work for us so we have taken care of all the codes if you taken codes with an id and all we need is uh let's go back to implementation review all quotes okay we need to know create for creating so for creating we are going to say uh post mapping right so user will make a post request to the service to our api so he is going to send a json object uh as a in the post request so let's see uh let's keep it as code code itself so uh when we have a quote and we are getting this so we are going to return what what are we going to written we are going to simply return code itself quote so that you will see what uh request that he sent will is it is assigned a new id or not right so i'm going to put this create quote so so for that so for that we need to check for request body so request body and in the request body we are going to see code and code right we are going to get code in the request body and we are going to return what uh quote service implementation dot create quote and we're going to pass quote in that and we're going to return this right so i think this is done we have uh did the uh this thing this thing and i think we did we did it everything yeah i think we have uh we have to also do the put this for updating right support mapping take this mapping and quote slash also pass has to pass the id so which code that he wants to modify right so let's simply call it as update quote and what is going to be the return type return type is going to be code itself all right uh so once he updated the code we're going to show him that okay this is the updated code for you right and we're going to need two parameters one is it request parameter that is going to be path variable path variable is going to be long id and at the request body the request body has to pass a code and quote right so once we have the code so we have to assign id so code dot set id off so what is the id that he is sent to the pathway right and once i said that you can simply say quote service implementation dot what is that update code right so pass id and passcode right so i think we have done everything and yeah i think we have to do delete as well so at delete mapping so this is where we expect a user to delete a tweet a code from our database right so this is ideally not the case not everything will have the access but for the demo purpose let's do that so what is the path that will return so slash uh quote right and has to pass id so idea of which thing that he wants to delete so once we have that so we're going to create a therefore that's a public so should we return what so i can think anything we can return simply here http response http http dot okay uh let's see written what should be done when we're trying to delete a tweet status status http status yep hit on http status and and let's say delete code and then let's take it path variable pathway and it's going to be long id so once we have that id you can simply say let's look at the implementation that we did for deleting what it will do okay we return http status so delete code so we are passing an id and it will return us http status no matter what return code service implementation dot so what is the delete port and id yep so this is going to return us http status and that is going to be not taken here and i think we are kind of done let's see so let's uh see the so one thing we have created a quote this is going to be entities is going to be a table right and we have created a repository that is going to extend the jp repository and using that we have created our service so this is our service that we are providing and its implementation we are taking that implementation into our risk controller right and for each mapping we are going to now use use uh these methods for that let's try and run this and we'll see each other and if it's working properly or not and let's debug that i am uh to be honest i am a newbie to the boot spring boot no it's been like couple months since uh sorry couple of weeks only since i started learning this but trust me this is the most interesting thing that i have seen in the recent times okay so we haven't got any errors luckily so let's go back to our let's try and to send hello so it is not going to return hello because we have removed hello right so but what can we ask api slash quotes you can say if a slash quotes sent so when i am trying to perform get request it is giving me null because right at this moment there are nothing in our database right so let's try and put something so put in a sense uh try add codes to the database so we are going to perform a post request right so in the body we are going to say and let's pass a json here right so id is going to be out of field date is also going to be autofill the only things that we have to return uh send in the body is one uh code so let's call it as quote and let's call it as this is my most inspirational quote of of all time okay let's go ignore the typos and author is going to be see uh have you know observed that the words that i am using are the names that i give to the columns right so that is where uh this column name columns are used so author is going to be myself so i'm going to say sorry prakash okay okay rdd so yeah so this is going to be my request and fingers crossed let's send that request and it is saying that it is not allowed api slash quotes post request why is that huh so so i have said quote here and here i'm using quotes like an idiot so if i send it as a quote yeah now you can see that it has uh sent that so oops i think we have made a mistake in our this thing so we sent a couple of two times ids let's go back to code id okay i regenerated value id okay nobody so we have an id here so let's uh send send coupler codes here so this is my most nutritional port of all time i'm sending it again so now this is given ideas two and again the timestamp is the published is changed so let's send a couple of them let's also try and change this right so we have sent six equations request has been successfully taken now let's perform a get request on quotes so i'm asking quotes because it will return me all the quotes right so there is something wrong go to our code and get mapping get mapping slash quotes get all quotes okay let's try and say what slash 2 something is not is the delete working okay i'm thinking for a moment hmm you okay quartz is working let's okay let's try we have one of the time so we have codes right so get mapping so i've set codes and i did a git mapping and when i did the get request it's going returning video empty list because there are no uh tweets and quotes at this time right so and the same thing happens if i try with slash one or two quote slash one now if i try this it's going to return me null because there is no tweet at no quote at one right so if i try and do the uh post at uh what is that post at q is it you okay q u t at a q u t and let's say this is my uh thing and let's send the post request and it is giving me id of one and it has taken my tweet and it is updated the author and the quote now if i come back and make get request on quote slash one yeah it has it is giving me the tweet right so i can again go back and do quotes it is going to retrieve me all the quotes so list of all the codes let's go back to post request and let's add some tweets this is my dopest port right and let's change the author to let's say snoop dogg okay so i sent this then it is saying that method is not allowed because it is post slash quote yep so when i say uh post on a post a quote so it has taken the code and it has it it has given me a response that the quote has been updated so now if i go back to get and say quotes here we go so we are getting all the quotes here so currently in our database we have two codes so one is from me and only from snoop dog and if i want to retrieve a particular quote i can say 2 code slash 2 here we go so we are getting uh tweet sorry code with the id 2 right now let's again test the remaining things so quotes is working quote id is working and post-op code is working so we need to test put and delete so put is where we try and modify a particular quote right so let's do that so um let's modify the second one so let's say put and we'll send this it is my this is my dog so yeah so you can see that when i said the put request the put request has taken a tweet uh sorry quote and it has updated the code so previously it was my dopest and now it is my dope right so now again if i perform the get so you can just see that in here right so the it is updated in the database as well right and the final thing that we have to test is the delete right and delete so would be slash quote on one right i think this is what we have designed yeah so we can delete a particular code at our particular id and it is going to return as http status that's it and fingers crossed yes so the http reverse is 200 so it is returning me okay so it has been deleted successfully so this is how you can build a production level uh production grade api so i have shown a very basic example here but trust me uh when you are working for an organization know which deals with a multi billion dollar projects like this gets quite populated and quite big and very quickly but at the same time it is very easy to manage once you follow this entire structure right so you can see this is why i like springboot where no we are separating our logic into different layers like no repository layer or this business layer or service layer this is like that so this is why i like spring boot and i'm planning to make um like no more tutorials on spring boot and if you want uh please no comment uh in the comment box i'll try and learn and bring some more uh dope tutorials on spring boot i think this video was pretty helpful if you're starting to learn spring boot i will upload this to my github and put will put a link in the description and please if you found anything useful here uh please subscribe to our channel right now you will get to see my videos in their feed and if you are not interested please don't watch right so i insist in people not watching a video if that is not no helpful for them right so i try and make a videos which are helpful and which i would watch right hence i wanted to keep this video slow right so i can if you want a quicker explanation you can go for 2x times explanation so that you can cover multiple uh knowledge it's at a smaller time so this is up for this video so we're able to you know create a full-fledged rest api which can perform all the code operations right and we are using in-house sorry in memory database and we are using spring boot to be able to do that so and i hope this video was helpful and thanks for watching we'll see you in my next videos with uh many tutorials like this and please leave a like if you like this video [Music] you
Info
Channel: Sai Prakash Reddy
Views: 600
Rating: undefined out of 5
Keywords: Rest API, Spring Boot, Spring framework, H2 database, Hibernate, spring boot microservices, production api, spring tutorial, spring tutorial for beginners, rest api tutorial, autowired annotation in spring, learn spring, learn spring boot, spring boot tutorial for begineers, java spring boot, java spring tutorial, spring mvc tutorial, spring mvc, spring security tutorial, spring boot 2, how to use spring boot, what is dependecy injection, spring boot initializr
Id: CmrtgHCwAVw
Channel Id: undefined
Length: 65min 7sec (3907 seconds)
Published: Sat Apr 17 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.