Hi. I am making a full-stack application with Ktor...
# ktor
d
Hi. I am making a full-stack application with Ktor, with both backend and frontend JVM based, so I decided to define the serializable (with
kotlinx.serialization
) domain objects exchanged over the REST API in a shared project. I would also like to define the REST API itself in there, with the paths, methods and objects expected/exchanged in various endpoints, so that it can be used both in the server and the client. I know about the
Resources
ktor plugin, but it lacks the ability to define the methods and contents of the bodies. Is there any third-party tool/plugin that does this or am I left to attempt to create my own? And is this even something sensible to do in the first place, or should I rather use something like OpenAPI to define the API in a platform agnostic way 🤔?
s
This currently is not possible, although it might be possible to build this into Resource but it requires more changes and improvements to Resource. Since what about different status codes, etc. I would say if you already have the common model defined in a common module, having the boilerplate of call
receive
is not that annoying:
👍 1
r
Does the API need to be shared externally or is it only for internal use between frontend and backend? If the latter, consider an approach that avoids all the marshalling to and from REST APIs, and just create RPC interfaces that send serialized data classes over the wire directly. We use kvision remoting for this on a project with a JS frontend (without the kvision UI stuff) and it handles all the boilerplate and code generation and integrates nicely with ktor on the backend. You just create the interfaces and backend implementations.