🛠 Build and Secure an API with Spring Boot and Kotlin
Tags: spring, kotlin, security
Published: 2021-08-20 13:39:58

### 📓  See how easy it is to #bootstrap a CRUD #API with Spring Initializr, build it with #Spring Boot and #Kotlin, and secure it with Auth0.

### <br>

**TL;DR:** In this article, you’ll learn how to quickly build a RESTful API using the Spring Boot framework and the Kotlin programming language. You’ll then use Auth0 to secure the API so that only authorized parties can use its key functions. You can find the final code for the project developed throughout this article in [this GitHub repository](https://github.com/AccordionGuy/HotSauces).

> **Look for the 🌶 emoji if you’d like to skim through the content while focusing on the build and execution steps.**


## Spring Framework, Spring Boot, and Kotlin: An Overview

Before we start building the project, let’s look at the frameworks and language you’ll use.


### Spring Framework

<img alt="Spring Framework icon" src="https://images.ctfassets.net/23aumh6u8s0i/6WdgKiAbhNyVIQWDECzf48/fc4dd3f38700ba0f9a143bdaee8c9479/spring_icon.png" align="right" style="padding: 10px;">

[Spring Framework](https://spring.io/projects/spring-framework), often shortened to just “Spring”, is a popular open source application framework for the Java platform. It’s built on the principle of [inversion of control](https://dzone.com/articles/understanding-inversion-of-control-and-dependency), whose name implies that control of a Spring application is the opposite of how program control works in traditional applications. Instead of your code directing the application and calling on functionality from a library, the framework directs the application and calls on functionality from your code.

This approach makes it possible to write an application as a collection of components, with the connections between them maintained by Spring. Spring provides a lot of ready-built components called _dependencies_ that provide functionality that applications commonly require. The end result is a system for building applications that are modular, flexible, quicker to write, and easy to maintain.

Spring is often described — especially by Java developers, who’ve grown used to working with unwieldy frameworks — as lightweight. It provides a set of built-in often-needed capabilities such as MVC, caching, messaging, security, and data access. It significantly reduces the amount of code you have to write and lets you focus on the functionality specific to your application.

While Spring is often used for web and server-based applications, it’s a general application framework and it can be used to write desktop and mobile applications as well.


### Spring Boot

<img alt="Spring Boot icon" src="https://images.ctfassets.net/23aumh6u8s0i/17rXel2g1r2rxiGkpeHNSy/dd64d06b65c7e095b6bcdeffecbd0a9f/spring_boot_icon.png" align="left"  style="padding: 10px;">

[Spring Boot](https://spring.io/projects/spring-boot) is a framework built on top of Spring that simplifies Spring development. It does this by enforcing an [opinionated](https://www.quora.com/What-is-a-Opinionated-Framework) approach to Spring application development through [“convention over configuration”](https://facilethings.com/blog/en/convention-over-configuration), the use of default setups that applications are likely to use, and a standardized application structure created by a generator that goes by the decidedly “Web 2.0” name of [Spring Initializr](https://www.tiobe.com/tiobe-index/). Thanks to this “it just works” approach, it’s the fastest way to develop applications with the Spring framework.


### Kotlin

<img alt="Kotlin icon" src="https://images.ctfassets.net/23aumh6u8s0i/1lE1Sn0pHAIa082QVEhJ0f/b4c6184a9387900f457d260d6e0aeb38/kotlin_icon.png" align="right" style="padding: 10px;">

[Kotlin](https://kotlinlang.org/) is part of the wave of programming languages that appeared in the 2010s, which includes [Dart](https://dart.dev/), [Go](https://golang.org/), [Rust](https://www.rust-lang.org/), and [Swift](https://developer.apple.com/swift/). These languages have a number of common traits including their own takes on object-oriented programming from the lessons of the 1990s and functional programming from the lessons of the 2000s, inferred strong static typing, and meteoric rises in popularity (all of them are in [TIOBE’s index of popular programming languages](https://www.tiobe.com/tiobe-index/), and all of them except Kotlin are in the top 20).

As a programming language designed by [a company that makes developer tools](https://developer.apple.com/swift/), Kotlin is unique in its origin. It was designed to be an [improvement on Java](https://kotlinlang.org/docs/reference/comparison-to-java.html), with many of the language features of [Scala](https://www.scala-lang.org/) (but faster compile times) and with the power and convenience that comes from interoperability with Java and the Java platform. It has grown to become the preferred language for Android app development; as of July 2021, [80% of the top 1,000 apps in Google Play were written in Kotlin.](https://developer.android.com/kotlin/stories?linkId=94116374) According to JetBrains’ [*State of Developer Ecosystem 2020* report,](https://www.jetbrains.com/lp/devecosystem-2020/) Kotlin is also making serious inroads into web and enterprise development territory.

Since Spring and Spring Boot are based on the Java platform, you can use them to build applications using any JVM-based programming language, including Kotlin. If Java’s verbosity is bringing you down, or if you’re an Android developer who wants to write the back end for your app but don’t want to switch languages, Spring and Spring Boot development in Kotlin is for you!

[Read more...](https://auth0.com/blog/build-and-secure-an-api-with-spring-boot/?utm_source=content_synd&utm_medium=sc&utm_campaign=spring)