https://github.com/alien-head/kleuth
kotlin + sleuth = kleuth. A framework for generating Spring REST APIs through the directory structure.
https://github.com/alien-head/kleuth
framework kotlin kotlin-language kotlin-library rest rest-api spring spring-boot web
Last synced: 3 months ago
JSON representation
kotlin + sleuth = kleuth. A framework for generating Spring REST APIs through the directory structure.
- Host: GitHub
- URL: https://github.com/alien-head/kleuth
- Owner: alien-head
- Created: 2021-03-11T02:17:41.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-05-23T15:53:40.000Z (almost 5 years ago)
- Last Synced: 2024-11-27T15:39:48.078Z (over 1 year ago)
- Topics: framework, kotlin, kotlin-language, kotlin-library, rest, rest-api, spring, spring-boot, web
- Language: Kotlin
- Homepage: https://alien-head.github.io/kleuth
- Size: 747 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Kleuth
[](https://github.com/alien-head/kleuth/actions/workflows/pr-verify.yml)
[](https://search.maven.org/search?q=g:%22io.alienhead.kleuth%22%20AND%20a:%22kleuth-framework%22)
[](https://ktlint.github.io/)
kotlin + sleuth = kleuth 🕵️♂️ . A lightweight, flexible framework for generating Spring REST API routes dynamically.
Visit the docs at [alien-head.github.io/kleuth](https://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:

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:
```kotlin
@Route
class GetPizzas(private val service: PizzaService) {
fun handler(): ResponseEntity> {
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:
```kotlin
@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:
```kotlin
@RestController
class PizzaController(private val service: PizzaService) {
@GetMapping("/pizzas")
fun getPizzas(): ResponseEntity> {
return ResponseEntity.ok(service.getAll())
}
@PostMapping("/pizzas")
fun createPizza(@RequestBody body: Pizza): ResponseEntity {
return ResponseEntity(HttpStatus.CREATED, service.create(body))
}
// ...
@GetMapping("/pizzas/{pizzaId}")
fun getPizzaById(@PathVariable pizzaId: UUID): ResponseEntity {
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!