Spine (my Ktor common code DSL) has a micro-module...
# arrow-contributors
c
Spine (my Ktor common code DSL) has a micro-module for Ktor + Arrow interop: https://gitlab.com/opensavvy/groundwork/spine/-/blob/main/server-arrow-independent/src/commonMain/kotlin/ServerRaise.kt?ref_type=heads Would you be interested in upstreaming this somewhere?
I seem to recall @simon.vergauwen had an experimental library for that somewhere?
y
I think that exists currently? It'd be great to update it though.
s
Spine >>> what we have 😅 In this case I think it's better fit in the Spine repo to be honest but I'd be happy to promote Spine from the Arrow-kt website!
y
It's already on the website btw. I think the point here is that this is a tiny module that doesn't actually have other spine dependencies, so it can be easily added to an Arrow integration module
c
Exactly, it's a micro-module just to call
raise
inside a Ktor server endpoint, which translates the call to a HTTP response
it's completely independent from anything else of Spine, and I'm sure it would be useful for Arrow users who don't use Spine
s
Ah sorry I didn't look at the code I thought it was the bigger Spine Arrow integration. We'd have to check what we have in the integration but yes I've love something like this its very close to my original minimal design of Arrow-kt Ktor integration that I was using myself.
c
The full Spine × Arrow integration can't live outside of the Spine repo because they are very deeply tied together for compatibility
(remember, it's the repo with union types and forwards-compatible type parameters 😅)
😄 1
p
It looks similar to what the
arrow-raise-ktor-server
module currently provides, albeit the
ApplicationCall.respondOrRaise
function will respond with the result of the lambda if nothing is raised, but otherwise allows you to
raise(Response)
(similar to your
raise(HttpFailure)
) to shortcircuit the handler.
👀 I didn't know that existed
p
so instead of
Copy code
routing {
    get("/ping") {
        raise {
            val value = call.parameters["value"]
            ensureNotNull(value) { HttpFailure("Missing value", HttpStatusCode.UnprocessableEntity) }

            call.respond("Pong: $value")
        }
    }
}
you can do
Copy code
routing {
    get("/ping") {
        call.respondOrRaise {
            val value = call.parameters["value"]
            ensureNotNull(value) { Response(UnprocessableEntity, "Missing value") }

            "Pong: $value"
        }
    }
}
❤️ 1
(or with an import,
ensureNotNull(value) { UnprocessableEntity("Missing value") }
)
c
Welp, I can just remove my interop module then, this already does everything I need 😅
p
There are also shortcuts for
getOrRaise("/ping") { ... }
equivalent of
get("/ping") { call.respondOrRaise { ... } }