Getting started with SparkJava
Let’s start with a Spark web application & Koin
SparkJava has now its Kotlin declination, and continue to assert its ambition for developing webapps in a smart & simple way.
Let’s go with the following Spark components to chain : a Controller, a Service and a Repository. All of those components assembled behind Spark with Koin.
- a Controller to handle http route and return result from the service
- a Service to handle business and take data from repository
- a Repository to provide data
Let’s go 👍
Get the code
First, add the Koin dependency like below:
Service & Repository
Let’s write our Service, a component that will ask Repository for data:
and our Repository, which provide data:
Finally, we need an HTTP Controller to create the HTTP Route
Declare your dependencies
Let’s assemble our components with a Koin module:
Start and Inject
Finally, let’s start Koin:
That’s it! You’re ready to go.
You have finished this starting tutorial. Below are some topics for further reading:
Also other getting started project: