Add JSON status endpoint
This commit is contained in:
@@ -17,6 +17,8 @@ kotlin {
|
||||
dependencies {
|
||||
implementation("io.ktor:ktor-server-core-jvm:3.1.3")
|
||||
implementation("io.ktor:ktor-server-netty-jvm:3.1.3")
|
||||
implementation("io.ktor:ktor-server-content-negotiation-jvm:3.1.3")
|
||||
implementation("io.ktor:ktor-serialization-kotlinx-json-jvm:3.1.3")
|
||||
implementation("ch.qos.logback:logback-classic:1.5.18")
|
||||
|
||||
testImplementation(kotlin("test"))
|
||||
|
||||
@@ -2,11 +2,24 @@ package de.ruvnox.tactical
|
||||
|
||||
import io.ktor.http.ContentType
|
||||
import io.ktor.server.application.Application
|
||||
import io.ktor.server.application.install
|
||||
import io.ktor.server.engine.embeddedServer
|
||||
import io.ktor.server.netty.Netty
|
||||
import io.ktor.server.plugins.contentnegotiation.ContentNegotiation
|
||||
import io.ktor.server.response.respond
|
||||
import io.ktor.server.response.respondText
|
||||
import io.ktor.server.routing.get
|
||||
import io.ktor.server.routing.routing
|
||||
import io.ktor.serialization.kotlinx.json.json
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
@Serializable
|
||||
data class ServiceStatusResponse(
|
||||
val service: String,
|
||||
val status: String,
|
||||
val version: String
|
||||
)
|
||||
|
||||
fun main() {
|
||||
embeddedServer(
|
||||
@@ -18,6 +31,16 @@ fun main() {
|
||||
}
|
||||
|
||||
fun Application.module() {
|
||||
install(ContentNegotiation) {
|
||||
json(
|
||||
Json {
|
||||
prettyPrint = false
|
||||
isLenient = false
|
||||
ignoreUnknownKeys = false
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
routing {
|
||||
get("/") {
|
||||
call.respondText(
|
||||
@@ -32,5 +55,15 @@ fun Application.module() {
|
||||
contentType = ContentType.Text.Plain
|
||||
)
|
||||
}
|
||||
|
||||
get("/api/v1/status") {
|
||||
call.respond(
|
||||
ServiceStatusResponse(
|
||||
service = "ruvnox-tactical-server",
|
||||
status = "online",
|
||||
version = "0.1.0-SNAPSHOT"
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user