Spine is a library to declare Ktor routes in commo...
# feed
c
Spine is a library to declare Ktor routes in common code :
Copy code
object Users : StaticResource("users", parent = Api) {

	class ListParameters(data: ParameterStorage) : Parameters(data) {
		var includeInactive by parameter(default = true)
	}

	val list by get()
		.parameters(::ListParameters)
		.response<User>()

	val create by post()
		.request<User>()
		.response<User>()
}
We can then call the routes typesafely in client code,
Copy code
val user = User("Test", active = true)
client.request(Users.create, user).isSuccessful() shouldBe true
and implement them typesafely on the server:
Copy code
routing {
	route(Users.list) {
		HttpStatusCode.OK to userRepository.list(includeInactive = parameters.includeInactive)
	}

	route(Users.create) {
		val result = userRepository.create(body)
		HttpStatusCode.OK to result
	}
}
In version 0.7.0, we improve the documentation.
👍 4
f
Ohhh Thank you so much for this!!! I've been looking for a library that has type-safe requests in kotlin, and not only type-safe routes.
c
It's a bit lacking in documentation right now, don't hesitate to ask me for questions or to create issues! My channel is #C078Z1QRHL3 here
❤️ 1