This post is for sharing code for a Youtube video.
This is the first video in a series about Spring Boot development in Kotlin. In this first episode we are going to create the project, write a REST controller and discuss hot swapping, an important tool that improves the development experience significantly. We are going to use Intellij IDEA Community Edition as an IDE. You can download it and use it for free.
package com.vladsave.firstboot
import org.springframework.web.bind.annotation.*
data class ViewAccount(
val id: Int,
val name: String
)
data class CreateAccount(
val name: String
)
@RestController
@RequestMapping("/accounts")
class AccountsController {
@GetMapping("/")
fun getAll(): Iterable<ViewAccount> =
listOf(ViewAccount(id=1, name="First"))
@PostMapping("/")
fun create(@RequestBody request: CreateAccount): ViewAccount =
ViewAccount(id=2, name=request.name)
}