Idiomatic kotlin preconditions for spring boot Res...
# server
a
Idiomatic kotlin preconditions for spring boot Restful API's I would love your feedback on this. If you could contribute any ideas by creating issues and providing constructive feedback, it would be immensely helpful. https://github.com/nextbss/requirekt
1
K 1
🎉 1
n
does this conflict with Kotlin's built in
require
function at all?
a
Good question, It does if you use both in the same file. Since they are in different packages it's unlikely to be an issue if you import the correct one.
k
honestly I think it is too much opinionated, I would assume it has some nice dsl for specifying preconditions, instead it ties you to specific exceptions and error handling in specific framework
a
@kqr What if it was less opinionated? How would you go about making it less opinionated? Besides it being too opinionated, what do you think of writing API preconditions for spring boot using this method?
m
I think your library is well designed, and If I understood correctly will provide me with a more specific
require()
oriented at Spring validation, as it encapsulates HTTP error creation, right? I don’t think it’s a problem being opinionated as the intended usage is very specific. Otherwise one can fall back using standard
require()
or a more generic lib like https://github.com/spoptchev/kotlin-preconditions edited
❤️ 1
👍 1
a
@Matteo Mirk Thanks, exactly what it is built for. If you have any issues please do leave an issue.
👌 1
m
I gave you a star and shared the link on my company Slack kotlin channel, we work extensively with Spring and more apps are being written in K , so maybe someone will find it useful
❤️ 1
a
@Matteo Mirk Thanks much!
k
I would say that most of the projects have their own exceptions and exception handling/error response representation
so if I would want to decouple it, I would say such a precondition lib should be able to throw custom exceptions and has some nice dsl for predicate like @Matteo Mirk send.
👍 1
a
@kqr Thanks for the feedback. I will look for ways to add custom error response representations.
m
@kqr those are nice improvements, maybe submit an issue or pull request to the project
👍 1
k
as of preconditions in API, I don't know. I think in API you could check some trivial stuff like nullability, length, ... which I guess is nicer via some validation annotations on DTOs
👍 1
rest of conditions I would move to business logic/value objects and so on
a
Custom error responses have been added. Checkout the changes and tell me you how you feel about this https://github.com/nextbss/requirekt