Hi Everyone, I'm fairly new to the backend and I'm...
# server
m
Hi Everyone, I'm fairly new to the backend and I'm looking for an easy way to build a json API. Is there a framework that would allow me to describe my API using some kind of description language and generate some code for me ? (I'm thinking at least serialization/deserialization, parameter checking and documentation generation, maybe also access rules). All the things I have seen so far are still pretty low level and require me to do the error prone json serialization/deserialization, etc...
s
open API 3 for api description it comme with a code générator https://github.com/OpenAPITools/openapi-generator
👍 2
d
there are several options which will allow you to build these kinds of APIs with swagger documentation and automatic (de)marshalling of JSON to data class structures, but they vary in their implementation - some use the code generator (think ktor/spring/vertx(?)/javalin do this), http4k also supports it but generates the swagger docs from the code.
which you choose kind of depends on style of how you like to construct apps TBH 🙂
m
@dave thanks ! Can ktor generate json (de)marshmalling code ? I missed that on their website
d
@mbonnin I'm not a ktor expert but I think you can simply to it via installing a feature. https://ktor.io/servers/features/content-negotiation/jackson.html Try #ktor for more help specifically 🙂
m
Ok thanks. For http4k, are you referring to contracts ? (https://www.http4k.org/guide/modules/contracts/)
d
yep. there are also links to example (apps) on the site but if you need any more assistence then try #http4k 🙂
m
Thanks ! I'll dig into these pointers
d
np
d
Also you can consider using GraphQL
m
GraphQL + graphiQL would be the other candidate indeed. My only fear is that it would be a bit more work overall (for clients + servers). Maybe it's just fear of change though.
Is there a de-facto graphql + kotlin stack ?
d
@mbonnin please think carefully before jumping into a graphql solution. do you actually need it?
(just my 2c obvs)
m
I don't know, what would be the downsides ? On the upsides, strong typing + introspection is nice and tools like graphiQL are nice as well.
d
Full disclosure, I haven't used it. But a team I'm in is planning to.
m
I've been doing graphql on Android for a while, it's a bit of setup but for anything bigger than a side project, the strong typing garantees are really useful
d
there is loads of material on the various trade-offs so I won't go into them here, but the main concern for me is jumping into a YAGNI-type solution before it's justified. first question I'd ask is - does the API you're building justify having a graph-data interface?