kresult-problem
Provides RFC7807 compliant Problem JSON support
By using a Problem
on the Failure
side of a KResult
, strongly typed HTTP problems rendering to application/json+problem
can be utilized:
import io.kresult.core.KResult
import io.kresult.problem.Problem
import io.kotest.matchers.shouldBe
fun test() {
val res = KResult.Failure(
Problem.NotFound(detail = "User with that ID could not be found")
)
res.onFailure {
println(it.toJson(pretty = true))
}
res.error.status shouldBe 404
}
Content copied to clipboard
The result looks like:
// application/json+problem
{
"type": "https://kresult.io/problem/not-found",
"status": 404,
"title": "The requested resource was not found",
"detail": "User with that ID could not be found"
}
Content copied to clipboard
Usage
Gradle Kotlin DSL:
dependencies {
implementation("io.kresult:kresult-problem:VERSION")
}
Content copied to clipboard
Gradle Groovy DSL:
implementation group: 'io.kresult', name: 'kresult-problem', version: 'VERSION'
Content copied to clipboard
Maven:
<dependency>
<groupId>io.kresult</groupId>
<artifactId>kresult-problem</artifactId>
<version>VERSION</version>
</dependency>
Content copied to clipboard