Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
src/main/kotlin/io/tekniq/rest
README.md
build.gradle

README.md

tekniq-rest

A tool utilizing jackson-mapper for making RESTful calls to web services.

Simple GET

val rest = TqRestClient()
val resp = rest.get("https://www.google.com/")
println("Status: ${resp.status}, Body: ${resp.body.substring(0, 50)} ...")

or with lambda

val rest = TqRestClient()
val text = rest.get("https://www.google.com/") {
  body.substring(0, 50)
}
println("Body Snippet: $text")

Data Transformations

data class Fiddle(name: String, height: Int?, birth: Date?)
val rest = TqRestClient()

val resp = rest.get("https://example.com/myCustomWebService/json")
val x = resp.jsonAs<Fiddle>()
println(x)

or with lambda using status checking for alternative result

data class Fiddle(name: String, height: Int?, birth: Date?)
val rest = TqRestClient()

val x = rest.get("https://example.com/myCustomWebService/json") {
  if (status >= 400) {
    null
  } else {
    resp.jsonAs<Fiddle>()
  }
}
println(x)

POST with headers

data class Fiddle(name: String, height: Int?, birth: Date?)
val rest = TqRestClient()

val payload = Fiddle("John", 42, Date())
val resp = rest.post("https://example.com/myCustomWebService/json", payload, mapOf(
    "Authentication" to "Basic ${Base64.getEncoder().encode("user:pass".toByteArray())}"
))
println("Status: ${resp.status}, Body: ${resp.body")
val x = resp.jsonAs<Fiddle>()

Logging Request and Response

This is useful for debugging or creating audit trails.

val logrest = TqRestClient(object : RestLogHandler {
    override fun onRestLog(log: RestLog) {
        println("LOG Request: ${log.request}")
        println("LOG Response: ${log.response}")
     }
})