Hey there, welcome back friends. In this video, we will try to understand how to create a RESTful API using Spring Boot. And this is definitely a very simple thing to do. Let me show you how we can perform this task. So let us start from the beginning, we will create a new spring starter project. And in here we will give the name as for example, setting up a RESTful web app.
And let us also give the artifact name same as the name of our project. Here we go. So this looks good to me. And apart from that everything is good enough let us click on Next. And in here because we are creating a RESTful API, we would require a dependency by the name of a web. Now, in here we have the section of frequently used and in your case, you may not get these options.
So in here, we can simply search for the dependency web. And under the section of a web UI will have couple of options. And one of the option would be fab, or right. And if we hover upon this particular, but we say option, it will also give you some documentation, and it will let you know that it is used to build a RESTful web service. So this is cool enough. Let me click on Next.
And we will click on Finish. All right. So this will take couple of seconds. All right, so the application is created. Amazing. And if I show you, there are a couple of files which got created automatically, which is cool enough, and one of the file has this application or Java file and this file is responsible and running the application.
Now this is good enough, the name is also okay, but we will change the name from application to blog app. This blog app will give us information related to our blog website, for example. So first of all, we need to make some changes, we will rename the Java file from application dot java to blog app dot java. And we need to also like modify the name in here. So it would be like blog app dot class, let me make the change real quick. Here people now things are good.
Now moving forward, let us quickly navigate to this servlet initializer. So if I show you the servlet, initializer. Again, there is this application dot class reference. So let us modify this as a blog app dot class. Now, our application is good enough. All right, so this looks good.
And now moving forward, let us quickly create a RESTful API in fact, so we will create a new class in here. And we will give the name of the package as our God studies he taught API and the name of the class as for example, Last entities here we go and that set at fact, so, this particular class has been created. Now, in order to create this class as a restful controller, the V is very simple, we will annotate this as rest controller, here we go and inside this controller inside this class, we will create a public method, return type would be string and name would be list blogs, here we go. So, this name is good enough and definitely we will return a very simple string to start with. So, we will return the string list of blogs in that set. Now, the last thing that we need to do inside this class as adding request mapping for this method now, so, let us again annotate this particular method as a request mapping and for We'll give the request mapping as for example, list blogs, a game.
Alright, so this looks good. Now friends, this is it, we are done, we have successfully created a rest controller. So if this is a complete RESTful API, then definitely we would be able to execute this as well. So let us start to execute our application. We will run this as a Spring Boot app. This will take couple of seconds.
Here we go. So our application is up and running. Let us quickly run or check this particular application. The URL pattern was list blogs, remember that. So in here, if I navigate to localhost then definitely there would be an error page. But if we navigate to the proper location, which is list blogs, then we would be able to see the text less blogs.
So definitely we are successful in creating RESTful API and this is so damn simple. Now friends in our next video we will try to understand how to return a list to the webpage and how the internal conversion from a list to a JSON file will take place. So something interesting is coming up. I hope you guys enjoyed this video. Thanks for watching. Have a nice day and take care