Kleuth Framework

A framework for dynamically creating Spring Rest Controllers.

License

License

GroupId

GroupId

io.alienhead.kleuth
ArtifactId

ArtifactId

kleuth-framework
Last Version

Last Version

1.0.2
Release Date

Release Date

Type

Type

pom.sha512
Description

Description

Kleuth Framework
A framework for dynamically creating Spring Rest Controllers.
Project URL

Project URL

https://alien-head.github.io/kleuth/
Source Code Management

Source Code Management

https://github.com/alien-head/kleuth/tree/master

Download kleuth-framework

Dependencies

runtime (7)

Group / Artifact Type Version
org.springframework.boot : spring-boot-starter jar
org.springframework.boot : spring-boot-configuration-processor jar
org.springframework.boot : spring-boot-autoconfigure-processor jar
org.springframework.boot : spring-boot-starter-web jar
org.jetbrains.kotlin : kotlin-reflect jar 1.4.21
org.jetbrains.kotlin : kotlin-stdlib-jdk8 jar 1.4.21
org.jetbrains.kotlin : kotlin-stdlib-jdk7 jar 1.4.21

Project Modules

There are no modules declared in this project.

Kleuth

Build Maven Central ktlint

kotlin + sleuth = kleuth 🕵️‍♂️ . A lightweight, flexible framework for generating Spring REST API routes dynamically.

Visit the docs at alien-head.github.io/kleuth or read on to learn more.


How it works

Kleuth uses project folders and naming standards to map functions to web requests.

Example:

Pizza Restauruant REST API

Classes annotated with Route or RequestMethod are then used by Kleuth to map the path set in the folder structure to functions.

This is what the rest/pizzas/GetPizzas.kt class in the above example looks like in the "handler" style:

@Route
class GetPizzas(private val service: PizzaService) {
    fun handler(): ResponseEntity<List<Pizza>> {
        return ResponseEntity.ok(service.getAll())
    }
} 

Kleuth also contains a number of helper functions to make route classes even more concise. The same route can look like this:

@Route
class GetPizzas(private val service: PizzaService) {
    fun handler() = ok { service.getAll() }
} 

This is a significant improvement over the standard method of creating Spring RestController classes, which can decrease in readability quickly:

@RestController
class PizzaController(private val service: PizzaService) {
    @GetMapping("/pizzas")
    fun getPizzas(): ResponseEntity<List<Pizza>> {
        return ResponseEntity.ok(service.getAll())
    }

   @PostMapping("/pizzas")
   fun createPizza(@RequestBody body: Pizza): ResponseEntity<Pizza> {
      return ResponseEntity(HttpStatus.CREATED, service.create(body))
   }
   
   // ...

   @GetMapping("/pizzas/{pizzaId}")
   fun getPizzaById(@PathVariable pizzaId: UUID): ResponseEntity<Pizza> {
      return ResponseEntity.ok(service.getById(pizzaId))
   }
}

A Kleuth route handler class is also a Spring RestController. This means Kleuth functions are completely compatible with Spring RequestMappings. These functions make use of PathVariable, RequestBody, RequestParam, and all other possible Spring function annotations and parameters. If for some reason Kleuth does not support a Spring feature, a RequestMapping function can co-exist in a Kleuth route handler class.

Benefits

Reduce Spring Boilerplate

Kleuth REST API routes are created through the directory structure. No more RequestMappings and monolithic Controller classes (Less annotations too!). This also means less work!

De-obfuscate Your REST API Structure

The structure of a Kleuth-mapped Spring REST API is clear from the package view. Immediately understand the flow of a Kleuth REST API.

Codify Best Practices and Organization

Kleuth helps enforce clear and concise development practices and project organization.


Check out the docs to learn more!

io.alienhead.kleuth

Versions

Version
1.0.2
1.0.1
1.0.0