Book Image

Building Applications with Spring 5 and Kotlin

By : Miloš Vasić
Book Image

Building Applications with Spring 5 and Kotlin

By: Miloš Vasić

Overview of this book

Kotlin is being used widely by developers because of its light weight, built-in null safety, and functional and reactive programming aspects. Kotlin shares the same pragmatic, innovative and opinionated mindset as Spring, so they work well together. Spring when combined with Kotlin helps you to reach a new level of productivity. This combination has helped developers to create Functional Applications using both the tools together. This book will teach you how to take advantage of these developments and build robust, scalable and reactive applications with ease. In this book, you will begin with an introduction to Spring and its setup with Kotlin. You will then dive into assessing the design considerations of your application. Then you will learn to use Spring (with Spring Boot) along with Kotlin to build a robust backend in a microservice architecture with a REST based collaboration, and leverage Project Reactor in your application. You’ll then learn how to integrate Spring Data and Spring Cloud to manage configurations for database interaction and cloud deployment. You’ll also learn to use Spring Security to beef up security of your application before testing it with the JUnit framework and then deploying it on a cloud platform like AWS.
Table of Contents (12 chapters)

Setting up a Git repository

We have installed the IDE and Spring Framework. It is time to start working on our project. We will develop a REST application API for Notes and TODOs. This is a tool that everybody needs. We will give it a name: Journaler API. Journaler API will be a REST application capable of creating Notes and TODOs with reminders. Many different applications, such as mobile ones, will be synced to our backend instance running this REST application.

The first step in development is initializing a Git repository. Git will be our code versioning system. It is up to you to decide whether you will use GitHub, BitBucket, or something else for your remote Git instance. Create your remote repository and keep its URL ready along with your credentials. So, let's start!

The following are the steps to set up Git:

  1. Go into the directory containing the project.
  2. Execute the following command:
$ git init .
  1. The console output will be something like the following:
Initialized empty Git repository in <directory_you_choose/.git>
  1. We have initialized the repository. Now let's add the first file by executing the following command:
$ vi notes.txt
Here we are using vi editor to edit notes.txt. If you are familiar with some other editor, use that.
  1. Populate notes.txt with some content and save it.
  2. To add all of the relevant files, execute the following commands:
$ git add .
$ git commit -m "Journaler API: First commit"
  1. The console output will be something like the following:
[master (root-commit) 5e98ea4] Journaler API: First commit
 
1 file changed, 1 insertion(+)
 
create mode 100644 notes.txt
  1. Use the remote Git repository URL that you have prepared previously with credentials, and execute the following command:
$ git remote add origin <repository_url>
  • This sets the new remote.
  1. Execute the following command to verify the new remote URL:
$ git remote -v
  1. Finally, push everything we have to remote, by executing the following command:
$ git push -u origin master
  • If you are asked for credentials, enter them and confirm by pressing Enter.