What's going on guys Asalam allayikum welcome to this course on Spring Boot. In this course I'm going to teach you the most popular framework for the Java ecosystem Spring Boot which allows you to build Restful APIs and web applications and all that good stuff in this course I'm going to teach you Spring Boot and we're going to learn how to create an API connect to a real database using Docker um and a database will be Postgres as well as using JPA so this is an overview of how to put all of these components together in terms of building a real API all right so if you're new to this channel go ahead and subscribe smash the like button so we can keep on recording content like this and without further ado let's get started before I start just want to say that we just released our brand new platform Migos Code 2.0 know and uh everything has been built from scratch new dashboard new courses new tools um new content blogs and pretty much everything that you need in terms of helping you succeed as an engineer so this is something that a lot of you have been asking and I felt in terms of taking Amigos to the next level we had to build this brand new platform and in fact if you want to gain a certificate this exact same course with exercises is available in our platform so go and enroll all right so for now let's go ahead and learn about Spring Boot for this course we're going to use IntelliJ which is by far the best IDE for Java and uh pretty much everything that has to do with the JVM so in our platform actually if I show you we actually offer a 3 months free Intelligj subscription so literally go to licenses and then right here you should see the actual key to use intelligj all right so once you have that you can go and redeem the license and then you have access for free months so as well with Intelligj what I'm actually using is the tool called toolbox so within this course here Intelligj developer guide I show you how to get up and running with Intelligj and the best way is to install toolbox so in here if I click on this icon you can see that in here I do have intelligj toolbox and basically this is how I manage all of the licenses for jet brains IDEs so you can see IntelliJ Goland Community Edition they also have free commercial use for Rusk Aqua and I think for yeah webtorm as well which is quite nice rider as well fornet and uh yeah so go ahead and um install toolbox and then also redeem your code for intelligj ultimate all right so once you do that which is very straightforward in terms of installing IntelliJ through toolbox go ahead and let me know but what I'll do also is I'll leave the links for everything that you need in the description of this video once you have IntelliJ installed let's together create a new project by pressing on this button in here then you'll be presented with this window and in here we have a bunch of generators that we can use so you can see we have a standalone Java application Cotlin Go Maven we have Spring Boo JavX Quarkos Ktor HTML React Express and all of that good stuff so for us what we need is Spring Boot and then here just pick a location within your file system so I'm going to leave mine under desktop and then here I'm going to say spring dash and then boot all right the other thing that I want to All right the other thing is if you want to create a repository go ahead and say create git repo and this makes sure that you have the actual code as a git repository that you can then basically push to GitHub for example so in my case I'm going to do this and I recommend you to store everything you learn so that you can use to build your portfolio the next thing is language so for the language you can use cotlin if you want i do have a course on cotlin which is really nice language but I'm going to stick with Java in here and then for the type you can choose gradal with cotlin or groovy or maven so let's just use maven and for the group ID here I'm going to say com.migos code so this could be your domain or organization or pretty much anything that you want all right or if you want to have the same thing as me just say comam amigos code and then for the artifact I'm going to leave as spring boot for the package name in here so what I'm going to do is I'm going to remove spring boot i'm just going to have com amigos code and then within the root I'll create basically some packages if I need to but I don't need a package called Spring Boot all right so for JDK if you don't have JDK installed Java Development Kit click on this button and then you can basically download a JDK so click on download and then here you can choose a version so currently the latest one is 23 i think this is experimental basically I think long-term supported versions are 21 17 11 and I think 1.8 if I'm not mistaken all right cool just download any version that you want really and it should just work so in my case I'm going to cancel out of this and you can see here I can pick the version so in my case I've got 17 21 and 23 installed so let's So let's just pick 21 and in fact to make sure that everything works um with no errors just make sure you have the exact same version as me so just download in here so download and then choose 21 and then for the vendor you could choose any but the one that I always recommend is Eclipse Teamurine so this was before Adop Open JDK but now they renamed to Eclipse Team so because I'm on M1 chips and because I'm on M1 chip and because I'm on Mac M and because and because I'm and because I'm and because I'm on the M and because um and because I've got the Mac M chips I'm going to choose this one if not just choose this one all right so let me press escape and cancel and then for the packaging just choose jar all right so basically this configuration right here you can see the server URL is start.spring.io so if I click on this it brings up this website and this is the spring initializer which is quite popular and basically Intelligj is just using that to bootstrap your project all right let me go back and we're good to go click next now we can choose the Spring Boot version just leave the default in here and then we can choose dependencies so from here you can see that they have a bunch of dependencies so the most popular one is web and this allows us to so if I so if I select web and you can see that allows us to build restful APIs using spring MVC all right let's just select this one for now we'll come back later and select other dependencies but for now let's just stick with this one and then say create and hooray you can see that so let me just close this you can see that's indexing and it's done so I don't know why I've got split pane in here let me just click on this button and we are good to go so from this point onwards you can see that few things in here are red and green and this is because of git right so I'm going to push all of this to GitHub so that you have access to everything at this point let's stop here and if you have any issues feel free to let me know otherwise I'll see you in the next one now let's go ahead and create our very first Spring Boot API so in here let me just close this and if I show you within the pom.xml you can see that in here we have dependencies have a look dependencies and if I put this full screen we have spring boot starter web so this allows us to create APIs if I close this and then open project under src and this is a Maven project by the way so you can see we have src main and then inside of main we have Java resources and then also we have tests in here and you can see that we have one class in here called application tests and this right here does nothing at the moment all right let me just close this and within Java we have application and this class right here called application has this annotation right here called spring boot application and within the main method spring application.run and then we pass the application.class in here so as you'll see with Spring Boot as well as Spring Framework it's all about annotations so understanding these annotations is crucial now for every single Spring Boot application you will have this annotation in here which basically if I open this so I'm going to press command and then navigate into it and you can see the keyboard shortcut for Mac OS as well as Windows and Linux and this right here is an alias for enable auto configuration component scan and I think the configuration so it's basically bundling these three annotations into one so yeah so let me just close this now and to create your first API simply add a new annotation at and then say rest and then controller and within this rest controller oops what am I doing there we're going to so within this application we're going to create a new method so I'm going to say public and then string and in here I'm going to say hello and then world and within here I'm going to say return and I'm going to basically say hello and then world and then spring boot all right with semicolon and in order for us to expose this right here as an endpoint i.e http get so we need to say at and then get mapping so this method right here is a rest endpoint now what we need to do in order to run this is let's just rightclick run or you can run from here from here or from here so either one just run the application and if everything goes well you should see that within the logs have a look tom card started on port 8080 with context path and then forward slash now it means that we have a web server which is running on this port and we can interact with it so let me just hide this and if you see within IntelliJ we have a rest client that we can use so no need to use Postman or any other REST client so here we can basically click on you can see this web icon in here i can click on it and we can generate HTTP client in here so request in HTTP client i can do this or if I in here open a project and what I'm going to do is so I want to so I want you to have access to this so here under the root I'm going to say new and then we can basically say HTTP request so I'm going to commit all of this so I'm going to say requests there we go and I'm going to and I'm not going to add this as yet so I'm just going to cancel and then you can see that this is an example of a get request if you want to have more examples you can see how to send post requests put so on and so forth so in my case I want to send a request so a get request to HTTP and then localhost 8080 so remember within the logs so so remember within the logs if I open the run tab have a look Tomcat started on port 8080 and then this is the context forward slash so HTTP the protocol local host so currently I'm running on my local machine and then the port is 8080 now if I run this have a look we have hello world from spring boot and this is your very first API I with Spring Boot all right if you have any questions feel free to let me know otherwise I'll see you in the next one all right so what we want to build is this API in here where clients can send HTTP requests using get post put and delete so get for getting data post for adding data put for delete and delete for deleting data or resources so currently we have our API which is running on 8080 it's not doing much it's just saying hello world but this is the beginning then what we want to do is we want to integrate a real database Postgress running on Docker and you'll see Docker in action as well and following the integration with OpenAI so we want to use some AI capabilities within our API ai is very popular these days so I want to show you also as part of this crash course how to integrate AI with your Spring Boot applications all right so for now let's get started now let's go ahead and define the model for our application where we want to have developers and then store these developers into our database so we're not going to focus on the database for now that will come later but now let's just define the model in here all right let's just open up IntelligJ all right within IntelligJ let's go ahead and create a new class under our root package and we're going to name this class as software and then engineer so this will be a class in here and that's because later we're going to use Spring Data JPA we could use records but I'll use records in a second when we send a request to our server so here let me just put this full screen and let's define some properties so private and then here it's going to be a string or actually let's just say integer and then ID which uniquely identifies an engineer and then private and then string name and finally let's just keep it simple private and then here let's also have string and then I'm going to say tech and then stack so this actually should be a list of strings but just to simplify things when we start to store when we start to store data into our database instead of instead of us having a one to many relationship we just store everything under text stack so you'll see this in a second so now let's create a constructor so we're going to have so basically if I right click generate and then constructor so here we can actually select every single property but also let's just first select none so we have the no R constructor and then here right click and then generate and we're going to say constructor select everything and then say okay and then here I'm going to grab this Ctrl G put this on new line and this is because my font is quite big so so I usually don't have the font this big and next let's generate the getters and setters select everything okay And finally let's just have the equals and hash code so equals and hash code there we go and that's it now I'm not going to have the to string because it's not advisable once we start to work with Spring Data JPA but again you'll see all of this in action in a second all right this is pretty much the class that we need to store software engineers so next let's go ahead and define the controller so that we can create an API that we can have maybe two software engineers so for now I'll see you in the next one now that we have this model right here called software engineer let's go ahead and start to build our API so here I'm going to create a new class and I'm going to say software engineer and then controller so with spring boot and spring this is the naming convention so anything that accepts requests from the clients or exposes rest api expo or exposes rest endpoints you should name them as controllers so here I'm going to press enter and remember before within our application we had the at rest controller so within our software engineer controller in here we're going to say at and then rest controller now for this rest controller we have to define at and then request and then mapping and we're going to say software software and then engineers there we go and if you want to say API slashv1 for versioning you're more than welcome so now let's create a method in here that will return that will return software engineers so public and then list so list of in here so I'm going to say import class and then here I'm going to say there we go and then this will return software so software oops and then engineer and then get engineers just like this and let's just return list of and then here I'm going to say new software engineer and we're going to pass ID1 and then the name let's just say Jamesa and then the text tag for James going to be JS node and then react And then tailwind tailwind CSS something like this let's have let's have someone else so comma oops and then take this there we go this will be ID 2 this will be Jamila for example and Jamea she's a Java back end so Java and then Spring and then Spring Boot just like that and then remove this now obviously this could go on and on and on but let's keep it simple and this would semicolon right here and we're good to go the last thing we need to annotate this method with at mapping so for retrieval so get requests get mapping to delete put mapping to update to delete delete mapping for post post mapping for put and then mapping for us we want to have this as get mapping and we're good to go let's now start the application there we go up and running let me hide this and go to requests.http and if you want to send another request so just copy that and then you have to denote this with the hashtag so three hashtags denotes a separate request and then here I'm going to say for slash API v1 and you can see that we get autocomp completion perfect if I send the request you can see that we have the result and this is an array of objects so this is JSON and you can see that this is actually handled for us like magic so this is the power of Spring Boot we don't have to define any configuration in terms of how to encode and decode JSON objects everything just happens for us behind the scenes and to be honest this is pretty much it all right now that we have the API that obviously we're going to evolve later in here we're going to have as part of the exercise i think we're going to have a delete mapping a put mapping so on and so forth but this is taking shape so for now I'll see you in the next one for this section in here I want to show you how to get up and running with databases Docker and Postgress so we want to install a database using Docker in here and the database engine will be Postgress and then you'll see how we can store developers to our database but also get developers of our database now here getting developers of the database doesn't mean really removing but it's just a slice that you see here but also as part of the exercises later I'm going to give you a task to delete of your database and also update of your database all right that's all for now i'll see you in the next one in this section let's learn what Docker is and how we can get a Postgress database up and running with Docker docker is a platform for developing shipping and running applications in lightweight portable containers so why use Docker well Docker gives us portability runs consistently across environments uses fewer resources than virtual machines easy to deploy multiple instances of the application it keeps applications and dependencies separate and also rapid startup and deployment with pre-built images so when it comes to deployment especially when you combine with Kubernetes this is a technology that you should know Docker all right so let's go through some of the key concepts about Docker so we have containers so these are lightweight standalone and executable package of the software so this could be Postgress this could be uh Java this could be Python this could be your own application package into a container so this is the executable then we have images so this is a snapshot of a container so from the image you create a container and this image contains everything needed to run the application next we have the Docker file so this is a script defining how an image is built so it's just a set of instructions on how this image is built and then from this image we can run containers and then we have also docker compose so this is a tool for defining and running multicontainer applications so you'll see this in action docker compose and then we have registries so these so these are repositories for storing and distributing docker images so we have many but the most popular one is Docker Hub but there are other container registries provided by Amazon AWS as well as GCP Azure and whatnot all right this is pretty much an introduction to Docker next let's go ahead and install Docker all right to get up and running with Docker is really straightforward just navigate to their official website and then they have some explanation what Docker is and whatnot but here also you can see that you can download Docker desktop so it's quite interesting so Docker is the number one most used developer tool so I actually didn't know this and I think they're quite right to be honest so in terms of us installing Docker we could do it through here so if you want to learn more about Docker also if you click on developers you can go to documentation and in here you can basically get docker as well so if I click on get docker it takes us to this page in here and then you can download for Mac Windows as well as Linux all right so go through the operating system of your choice so I'm on a Mac i just click on Mac and then here you can see that I can download for the Apple silicon or Intel chip and also Windows in here you could just find the correct installation but go through the installation process it is very straightforward and once you install Docker I'll see you in the next one all right once you have Docker installed you should see Docker Desktop so here let me just open Docker desktop in here and it's an application that looks like this so here you can see the list of containers images volumes builds extensions and whatnot so currently I only have one or actually have a and currently I have few containers up and running in here so this is stuff to do with Superbase but I'll show you how we can get our container up and running in a second so once you have Docker Desktop you should be good to go but also one thing that I want you to do is if you open up the terminal and then I want you to type docker- dash and then version all right so this right here is the current version of Docker that I have installed maybe for you it might be something way higher than this i can't remember the the last time that I actually updated Docker but you should have the output like so and this means that Docker is now successfully installed in your machine with this it means that you can say Docker and then image or images you can basically say Docker ps as well and some of the available commands that Docker has to offer cool one other command that we're going to use is docker compose that you'll see later but um this is pretty much it and I'll see you on the next one all right so in here I'm inside of the docker registry and this is where we can find the docker images that we can run containers from and here you can see that they have a bunch of images so for machine learning and AI OAMA PyTorch TensorFlow and you can see that they have Alpine EngineX MySQL Postgress so literally they have a bunch of containers in here that you can use so the one that we actually need is this one called Postgress so let me just click on that and you can find the link for this under description of this video so here you can see that they've got these tags in here so 17 so these are the versions actually but also you have always latest in here all right so latest so what I want to do is let's go ahead and open up intelligj and within intelligj let's open up project and what I'm going to do is under the root folder in here spring boot i'm going to create a new file and we're going to name this as docker dash and then compose dot and then yaml all right now under the description of this video you will find the contents for this YAML file so just copy and paste all right perfect so once you do that you should have this in here and this basically is just a way of defining the containers that we want to manage with Docker so here instead of writing the command so docker and then run I'm just using docker compose so here I'm defining one service called database i'm naming it as posgress and you can even say posgress dash and then spring boot so I think maybe I do have a database called postgress so also this is the image so postgress oops not that but postgress and then latest so this is the version right so within DockerHub in here you saw that we have the versions or tags so 17.2 17 latest and whatnot so if I go back I'm going to keep this as latest and then here I'm defining the Postgress user the password and then where I'm actually storing the data and then some volumes and then the ports in here so by default Postgress runs on 5432 but I'm changing this to 5332 because some people might have this port already in use and I've been getting a lot of questions that basically I cannot run Postgress on docker because it doesn't connect and it's because of this right so you can change this port to anything but this one has to be 5432 and then some networks and then the restart policy see in here and uh this is the network so if you have more than one container and you want them to talk through the same network you can just um define network like so and then use it and then this is the volume and to be honest it's as easy as this now let's go ahead in here and open up terminal right within Intelligj and I'm going to say ls and you can see that we have the docker compose.yammo and now I can say docker compose and then dash and then up dash and then d so d for detached so if you execute this command you should see that we have network created volume created and then postgress spring boot and then started all right now what I want to do is I want to say docker compose and then ps and if you see here have a look we have one container which is running postgress- spring boot and this is listening on localhost 5332 this is the image in here and basically is up and running so what we're going to do also is if you want to check the logs for this container we can do as follows you could just say docker compose and then logs press enter and have a look database system is ready to accept connections and with this we have a database up and running hooray now that we have Postgress running on Docker next let's go ahead and connect our Spring Boot back end to our database so let's open up IntelligJ and in here let me hide this and if I and if I open a project what we're going to do is under src main resources and under pom.xml we need to add few dependencies so here you can see that we have this button called add status click on it and it brings this window that you've seen before and if I go to web you can see that spring web is selected that's the one we did before but we want to work with SQL and databases but we want to work with SQL databases just go to SQL and then here we want to choose both SQL driver so a JDBC and R2 DBC driver that allows Java programs to connect to PostgresQL database and also we want to use this right here spring data JPA so this in here allows us to persist data in SQL with Java persistence API using Spring Data and Hibernate you'll see this in a second all right perfect just press okay and we're good to go so this actually reloads the changes and sometimes if you add these dependencies manually you have to reload changes so if I scroll down you can see that in here we do have the dependencies that we added so in fact you can grab this from the description of this video and copy and paste but if I remove these you can see that this button shows up sync maven changes so I just do it so you can see now say that you paste from description of this video and then you have to sync Maven changes like the like that but technically you don't have to use this button in here if you don't want to all right so this is it next let me go ahead and restart the application and this will fail and you can see that in here fail to configure data source URL well that's because we need to add the configuration and tell our Spring Boot backend how to connect to the database i.e the URL username and password all right so for now I'll see you in the next one okie dokie so in terms of configuring the application to connect to our database let's hide this and then I'm going to go to project open up src main resources we have application.properties properties open that up and in here we can specify configuration that defines how our application behaves so here we have application name if you want to change this to whatever name that you have or the name of the service that you are building go ahead and do so so in my case I want to specify spring data and then source so you can see that under data source so data source dot we have few things so we have the URL which we want to specify so this will be JDBC colon for and then postgresql colon/ slash localhost colon and then 5 4 or 5332 so remember if I open docker compose remember this in here that we done 5332 so this is what we need all right so let's go back and also actually let me just show you so if I open up the terminal so remember if I say docker compos ps have a look so this is what we need locost 5332 so let me go back in here and 5332 and then here I'm going to say forward slash and then amigos so we need to create this database within our database server in a second but I'll show you how to do it next we need to define the data source dot and then password so this is going to be password and also duplicate this and we need the username and this will be amigos code amigos code amigos code like so and basically within docker compose the username is amigos code and the password is password like so all right let me go back all right now let me go ahead and define few things so this is more to do with JPA but if I try to start the application it will fail so here we need to specify JPA dot and then hibernate and then auto DDL so here I'm going to say create drop so this basically will wipe the database every time that we start the application and also we need to specify JPAN properties and the property that I want to have in here is the dialect so the dialect for this is going to be org dot and then hibernate dot dialect dot and then postgrql and then dialect and we can format the SQL as well so here I want to say hibernate and then formats SQL and this is going to be true so you'll see all of this in a second and to be honest you don't have to type none of this so I usually don't remember much of this and uh I just copy and paste from project to project and also we need to show SQL so let's just say true and I think finally what we need is so in here sometimes it asks us for the driver so let's just say yes so the driver name so I think this is driver and you can see that because it has it in the class path it encounters the it finds the postcresql driver and to be honest this should be it now let's try and start the application and by the way just grab all of these from the description of this video and you're good to go now if I start the application so I'm going to run the application and this will fail so if I scroll up you can see that database amigos does not exist have a look does not exist so this is actually very straightforward to fix and uh let's go ahead and create this database in the next video in order for us to create this database called amigos we can do it by specifying a property here that overrides the default database name or if you want we can also create it manually so or if you want we can do it manually to do it manually or if you want we can do it manually so let's just open the terminal and in here we can say docker compose and then ps grab the name of the container running say docker and then exec-it or ti paste the name and then say bash and then compose and then ps the name of the container which is running the database and then say docker and then exec-it so dash dash it if I'm not mistaken and then paste the container name and then say bash press enter and it looks like it's not d-it but I think it's dash ID there we go so now you can see that we are in so if I type psql we cannot connect to the database as root so if I clear the screen ctr l now if I say psql dash and then u in here for the username amigos code press enter you can see that now we are inside perfect now if I say back slashl you can see that we have all of these databases now theoretically so you can see amigos code postgress and then template zero and whatnot now obviously here I could have just said basically if I go back I could have just said amigos code in here but I didn't want to do that because you might have a different username so basically it takes the username and it creates the database of that username so basically maybe the username is fu and the database name is bar so therefore it would have failed anyways right so now you know what is going on so let me just press Q in here ctrl L and I want to say create and then data base and here I want to say amigos and then end this with semicolon press enter and we're good to go now this should be amigos and let's try and start the application and this time you can see that hooray we managed to connect to our database so if I put this full screen in here what I want to show you is have a look so this in here has to do with the database so Ekari data source starting added connection and then started completed and you can see that all right so we don't have to specify the dialect anymore which is fine and we're good to go so the application started on port 8080 so this is actually telling us so if I go here It's telling me that I don't need this anymore so let's just get rid of that restart and you can see that error went away and we are good to go perfect this is pretty much it now in here basically if I say back slash L you can see that we have the database called amigos if you want to connect to it back slash C and then amigos and now we are connected to Amigos and then we can perform an insert statement and all of that good stuff which I'll show you in a second all right so we can use SQL in here to add data and then use our API to fetch data from and then use Spring Boot to fetch but you'll see how to perform CRUD with Spring Boot all right let me hide this and this is pretty much it i'll see you on the next one so far we have our Java class in here with three properties ID name and text stack and what we want to do is the ability of storing data so storing software engineers into our database so effectively we want to use spring data JPA and then map this class in here taking all of the properties ID name text stack and then create a table onto our database so here you can see ID name and then text stack now we're not going to create the tables ourselves we're going to let Spring Data JPA do all of this for us so Spring Data JPA is a framework that simplifies database interactions by providing a high level abstraction over JPA and this allows us to reduce boilerplate code and it provides also easy implementation of CRUD operations so we don't have to write any SQL whatsoever and it's much easier to work with all right let's go ahead and learn how to integrate this within our application within Intelligj what I need to do is to open the software engineer class and in order for us to get up and running with JPA and then be able to perform credit operations using the classes provided by the framework we need to first annotate this class in here with at and then entity so we're going to name this as at and then entity and you can see that we have you know a special icons in here and also this now is complaining so it says that persistent entity must have a primary key so what we're going to do here is for the ID we're going to say at and then ID just like that and now you can see that here we have a so this basically it's an entity so basically if I click on it it shows and here you can see that we have the key denoting a primary key and this right here and this sorry the text stack name and ID these now are columns in our database so it's as simple as this now if I restart the application what I want you to see is the following so if you see now we have create table software engineer ID integer not null name text stack and we have a constraint in here of primary key which is really nice so by just adding those two annotations we get a table created in our database so if I in here show you something so remember within the so within the resources application.properties so remember we added JPA hibernate DDL auto so basically this every time that we restart the application it destroys the schema and it creates it again in here formats SQL and then show SQL so if I remove these you won't be able to see the SQL so the SQL with the SQ the SQL which is in here all right so this is basically what these properties are doing so one other thing I want to show you is if I navigate to the terminal and in here remember I'm connected inside of my database and in fact if I say back slash q and then back slash or actually uh control c or no sorry ctrl d two times and if you want to bash into the container so we say docker exec it and then postgress spring boot and then bash and then type psql- U and the username that I defined under docker compose so my username was here postgress user amigos code so just type amigos code perfect now we have a database called amigos i'm going to say back slash c and then amigos so we are connected to amigos and now if I click the screen I can type back slash and then d software and then engineer press enter and you can see that we have a table called software engineer and you can see the types in here so on and so forth perfect so this is cool next what we're going to do is I'm going to show you how to fetch data from our database in here so for now if you have any questions drop a message otherwise I'll see you on the next one in order for us to interact with this underlying table in here called software engineer and the public so this is the schema from our spring boot API we need to create a class so in here let's say create new and then this will be a class and the type will be interface and here I'm going to say software and then engineer and then repository all right so this interface in here we're going to so let me just hide this we're going to say extends and then here we can say JPA and then repository so we have JPA repository and also we have CRUD and then repository so let's use JPA repository so JPA repository and here so on a new line actually because my font is quite big this takes few things so first it takes T so if you work with generics so this should be familiar in here so T so here this will be software engineer and then we have to specify the data type for the key so the data type for this entity so for the actual key is integer so let's just go back and then say integer so integer just like that and we're good to go now there's also uh some other interfaces that you can explore and um basically extend but for this crash course let's just worry on let's just use JPA repository and this is more than enough and I'll leave some instruction and I'll leave some text in terms and and I'll leave and I'll leave a comparison between these other interfaces that you can explore cool now let's go to project and within project and within project let's create a new and then java class and this will be software engineer and then service so this class will handle everything that has to do with business logic perfect here let's just say add and then service so this annotation right here it basically makes this class available as a bean so that basically spring instantiates it and then it makes it available to use within other classes all right the other thing that I want to do here is I want to say private and then I want to get the repository that we've just created so software engineer repository and then just call it software engineer repository so long name I know and now here we're going to add this to the constructor like so and so this is the danger when you have like big names so things don't really fit on the screen and it's kind of and it's kind of ugly but hopefully you can see it properly all right now let's have a method so here I'm going to say public and then list of and then software engineer and let's import that class and I'm going to say get and then software engineers perfect now this method in here is going to use the repository so we're going to say return and then the repository so software engineer repository dot and then have a look so we have find all we have find by ID or find all by ID and then get software engineer by get by and then find by save count exists find by ID find one so on and so forth and you can see that this is really straightforward and behind the scenes it's just writing some SQL to fetch data for us so think about what do we need right now so we want to get all software engineers well for that we could just say in here find and then all so we have a couple implementations in here so find all and then we can pass an example but for us let's just say find all nice and easy and we're good to go now let me just uh say that actually let's just make this final so in here we are returning software engineer which is an entity usually you don't want to do this usually you don't want to do this you want to map into a DTO so data transfer object for the client because let's say that this class in here has for example a password or it has things that you don't really want to return to the client so so by doing this you are exposing pretty much your table so usually you'd have a DTO and then you say dot and then stream so stream oops so stream dot and then map and then you map to a class that you can a class that you can then return to the client but for us this is very straightforward and simple and if you want to learn more about this I cover this in all of the other courses perfect so find all and let's now open up the controller so software engineer controller and before remember we add these two but now what we're going to do is let's get rid of all of these and instead what we're going to do is we're going to use the software engineer so software engineer service and you can see that Intelligj is quite clever and it brought the class in here as well as the constructor dot and then get software engineers so this actually should be get all software engineer so this should so this should actually be get all software engineers so let's just say get and then all software engineers get and then all software engineers nice and easy cool and to be honest this is it if I restart the application and then remember we have the so this file in here so requests.http and let me just hide this if I get have a look we get an empty array and this is because the table is empty cool let's carry on on the next video so you saw that the array is empty and this is because if I open up the terminal and within my database I can say select star from software engineer and have a look we have zero rows if you want to insert just say insert into and then software engineer and then here I'm going to say name comma and then tech stack and here I'm going to say values and let's just say here James and make sure that this has single and make sure that and make sure this and make and make sure that this is single quote and then the text stack let's just say JS comma and then node comma and then react for example and in here parentheses now if I try and save this this will fail because it says no value in column ID so open up the so we have to change the software engineer and here we just specify the ID but if you want the ID to be autogenerated just say at and then generated value and we specify the strategy and the strategy is going to be identity so if you want a sequence you can have a sequence and if you want a UID you can also have a UID but I think we could just say identity in here and then if I refresh this I think this should work so if I open up the terminal clear the screen and then press enter and you can see that it works perfect so if I add someone else so here let's just say Jamila so Ja and Jamea she she's into let's just say Java and then spring press enter and now I can say select star from software engineer press enter and you can see that we have one and then two so this is what this is doing all right so by just having the ID the keys do not auto increment Perfect so if you want a UID just change this to a UID and job done and with this if I go to services and actually let's just go to our requests.http and before we got an empty array now if I send the request haha have a look we are reading data from our database so James and then the text stack is JS Node React Jamila Java and then Spring cool this is pretty much it i'll see you in the next one okie dokie now let's go ahead and implement the ability of adding new software engineers through an API endpoint so let's begin by defining the endpoint so here we're going to say public and then void we're not going to return anything and this will be add new software and then engineer and here we're going to accept a software engineer so here I'm going to say software engineer there we go and in here have a look we are basically accepting the entity so remember this right here is an entity so usually we don't want to do this but for the sake of this video let's just uh use this nice and easy and it works and also we cover with other courses and bills that we have the way of doing this with DTO so data transfer objects so the same way that goes from server to client the same goes from server or the same applies for client to server perfect now in here I want to say software engineer and then dot service and then dot and I'm going to say insert software engineer and then pass the software engineer nice and easy and in here if you put your mouse in here you can see that you can create the method in the service class so let's just do that and there we go software engineer let me just put this on a new line and as I said my font is quite big cool the other thing that we need to do is to simply invoke the repository so repository dot and then guess what save and then we're going to save the software and then engineer nice and easy so here we're not even doing validation checking whether the values are not null and all that stuff which you should do but this allows us to but this allows me to demonstrate how to build a cred API which is the power of spring boot which is so quick cool so let me just go back into the controller and one thing that we need to do within the controller is we have to annotate this with guess what at and then post mapping nice and simple and job done so let's reload the application perfect let's go back to our request.http and if you want to send a post request it should be as simple as adding a new request and then you can say post and obviously in here the URL is going to be the same and if you want to find out how to send a post they've got examples click on examples post requests and here we could just basically take this example and then take this and then pass it in here remove the URL in here and we're good to go now for us we want to pass the name so let's just say JA and Jame's into Java and then Spring Boot and let's just say Spring for example cool now one thing I want to show you is so you see that we have a post request and then here content type application.json JSON this is the JSON object and if I show the examples once more so post request examples have a look send post with request send post request with JSON body so this is the body now we want to take the body that we have in here so this is the JSON body and this should be actually text stack so whoops tech and then stack so we want to take this body right here and within the controller so within the controller so right here we want to map into a J into a Java class so the way we do it is by saying at and then request body nice and easy let's reload the application once more and then go back to requests.http for HTTP and we can send this request so if I send this request you can see that hooray 200 status code and now if I send a get request in here so get all software engineers you can see that we have one JA and basically it's working so let's just send in here Alex and Alex in and Alex is into K DB and here and then databases and then and then Q so if I send this request you can see that 200 status code it worked if I select here get and basically play this you can see that we have Alex in here so this is coming from our database and I'm not lying to you so if I go to terminal and let me clear the screen select start from software engineer and you can see that it's been stored correctly and we have basically getting this data using spring boot and sending it back to the client cool this is pretty much it if you have any questions drop a message otherwise I'll see you in the next one say that you want to get a software engineer by ID so let's learn how to do that so here I'm going to hide and I'm going to go to the controller and we're going to have another method so here let's just basically take all of this paste and then I'm going to say get software engineer by ID and from the client we're going to receive the ID so integer and then ID and this is going to be at and then path and then variable and we need to in here specify the variable so just have double quotes and then curly brackets and then say ID so when the clients they send the request they say forward slash and then id and I'll show you this in a second now we can take this ID and then here we can say get and then software engineer so engineer by ID I can create this so put the mouse in here and then create method and here so this method actually let me actually delete this and do it again so we need to pass the ID inside so ID now let me just put the mouse in here again create the method and you can see that it gets sent through perfect so now we need to say return so return and then software engineer repository guess what so can you think of the method that we need so we have find find all and then here we have ah have a look have a look have a look find by ID hooray cool so let's just in here say find by ID and then here we're going to pass the uh ID now this will fail and that's because we are not really returning a list but we want to return the software engineer and here what we're going to do is say dot and then or else so or else we want to throw so or else throw an exception and then basically new and then illegal let's just say illegal is a state exception but obviously this is not the right exception that we should be throwing and we cover exceptions in detail so oops sorry my font is quite big and uh we get these helpers in here so this is not JavaScript just like that that's why so here I can say so let's just um on a new line we can say id plus not found just like that just like that and we semicolon and we're good to go so if we go back to the controller and this should return the software engineer like that and the error goes away perfect let's just rerun this there we go if I open up the HTTP client let's just send Alex done alex has ID one so if you want to send the get request with ID one all you do is take this and I'm going to paste it right here and then say forward slash and then one nice and simple send the request and you can see that we have Alex in here now if I say two so this will fail and we have in here the error now obviously this is not a 500 and by default this is how it's implemented and obviously you want to change this to HTTP status code 404 and this is something that we cover in great detail within our building spring boot APIs course but I'm going to leave it here this is pretty much it i'll see you in the next one hopefully now you can see the power of Spring Boot if you want to continue with the exercises there's an exercise where I want to challenge you in terms of building the rest of the API go ahead and enroll on the website where you can find the exercises as well as with solution and uh basically this course is part of the massive road map that we have for the Java and Spring Boot developer so basically we have a bunch of courses that basically takes you through from complete beginner all the way to deploying your applications to AWS including Docker Kubernetes and um basically the the whole sheban really all right it's all for now as always don't forget to smash the like button comment down below and I'll see you on the next one