Welcome & Instructor Introduction
All right, hi there and welcome to this Spring Boot and Kotlin tutorial series. Now, obviously I'm not Bucky, but just bear with me for a minute here. My name's Peter and I'm part of The New Boston community. So I contribute to the digital currency, to the Kotlin SDK, and also I contribute as a YouTube educator, which gives me the chance to teach you something on this channel.
Now, when I don't do this, I also work as a full stack developer and I work as an online teacher on the side. So I have courses on my own platform at codalong.tv, on Udemy, and some other sites. So hopefully I can give you a nice and gentle introduction to not only Kotlin but also to Spring Boot in this tutorial series. So without any further ado, let's just get into it.
The Spring Ecosystem: Framework vs. Boot
Alright, so here we are on the official Spring website at spring.io. On here, let's go to Projects and click on Overview. So here you can see that Spring really is an entire ecosystem of different projects that are tailored to different use cases. And the ones that we're really interested in for this tutorial series are Spring Boot and Spring Framework.
At some later point, maybe I'll also cover Spring Security to handle authorization and authentication to your application. But for now, let's understand the Spring Framework and Spring Boot, at least at a very rough level. So the Spring Framework really comes with lots of infrastructure that you typically need for enterprise web applications in Java. So it provides things like dependency injection, transaction management, accessing different data sources, and many, many other things.
Now, this Spring Framework is really extensive, so it can be hard to get started, can be a bit overwhelming at first. So I hope that this tutorial series is also kind of like a gentle introduction to the Spring Framework. But also, we're going to be focusing on Spring Boot. And the whole purpose of Spring Boot is basically to allow you to get started building web applications using the Spring Framework more easily by providing an opinionated view of building these kinds of Spring applications.
So this means there are lots of defaults defined for how you configure stuff and it really makes it a lot easier because it narrows down the solution path that you have for building your web application.
Project Goal: Building a Banking REST API
All right, so with that out of the way, what we're going to do in these tutorial series is building a REST API, a little web application with a REST API for banks. So in order to fit into The New Boston community, we're going to take digital currency as the domain for these examples.
So we're going to build a REST API that knows how to handle bank objects. So you can fetch banks from the REST API, you can create new banks, update existing bank data, delete banks, and so on.
Live Demo: The Completed REST API in Postman
So let me show you what this will look like once we're done. So over here in Postman, this is a tool that allows you to make different types of HTTP requests. So you can make GET requests, POST, PUT, DELETE, and quite a few others. And we're going to talk about what these mean in the coming tutorials. But for now, you can see here we have a REST API with our service running on localhost on port 8080. And if we make a call here, let's say to the banks endpoint, this will give us a list of all the banks that are currently known to the service. So we have three banks that are set up. These consist of an account numbers, transaction fee, and trust. It's not so much about data, you could add different types of data, of course, if you want to. You can also fetch a single bank by appending the account number of the bank you're interested in. And then you can see over here the REST API will respond with just the bank that you requested.
And similarly, you can also create a POST request in order to create a bank. So with this over here, you can give it the data it wants or you want it to add to the available banks, send it, and then if we go back, you can also see here the response is 201 Created. And now if you fetch all the banks, you can see you now have those four banks over here.
You can use a PUT request in order to update an existing bank. So over here, what does it currently look like? So this with the account number here has a transaction fee of 10 and 80 currently. So now let's use a PUT request for this bank with this account number and change the transaction fee and the trust. So if we send this over, you can see it's acknowledged by the REST API by giving you the same thing back as the response. And now if I go back and get all the banks again, you can see the transaction fee is now three and the trust is now 85.
And then lastly, what you're also going to build is a DELETE endpoint. So on this REST API, you can delete a specific bank again using the account number as an ID, and that's going to give you 204 No Content. And if I go now back to retrieving all the banks, you can see it's now back to only three of them.
Generating the Project with Spring Initializr
So all of this is what you're going to be building over these next few tutorials. It's going to be a really nice introduction into building REST APIs using Spring Boot and also how to test your applications using JUnit 5.
So with this little overview done, let's go to Projects and down here click on Spring Initializer. Now, this is a really useful tool to get started with a new Spring-based project by allowing you to say which kind of technologies you want to use, which Spring dependencies you want to include, and then it's going to generate the base project for you.
Now for these tutorials, let's go ahead and create a Gradle project, and of course we're going to use Kotlin. So don't be afraid if you've never used it before. That's also part of this tutorial series to just get your feet wet using Kotlin and building your first application with it.
Let's also go ahead and choose the latest snapshot over here of the Spring Boot 2 point something version. We're only going to be using very basic functionalities of Spring Boot, so I don't expect any major changes in any of the 2.x versions. So feel free to use a newer version if you have one available as well.
Then down here, I'm going to go ahead and set my group ID. So here again, the convention is to use your domain name, for me that's codalong.tv, in reverse order. And then let's say tutorials.springboot and then as the artifact ID, let's go ahead and say "thenewboston". So this is a Spring Boot tutorial series for The New Boston. And then for packaging, I'm going to use JAR. And I'm going to leave the Java 11, which is the current long-term support version, so I'm going to leave that there.
And then we just want one dependency over here, which is Spring Web. So as you can see, there are many different dependencies you can choose from, and Spring Web is the one that allows you to create RESTful applications or REST API, exactly what we want to build here. And it's going to use Tomcat as the default container.
So let's select the Spring Web dependency and then hit Generate, which is going to give you the base project as a zip file. So let's just go ahead, download this, and then please just extract it into a folder wherever you want to have your project on your file system. And with that, you have your base project ready. So in the next tutorial, let's go ahead and finally write some code.