https://kotlinlang.org logo
Title
a

AlexJuca

09/02/2020, 4:05 PM
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
:kotlin: 1
🎉 1
1
n

nanodeath

09/02/2020, 4:17 PM
does this conflict with Kotlin's built in
require
function at all?
a

AlexJuca

09/03/2020, 6:00 AM
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

kqr

09/03/2020, 7:43 AM
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

AlexJuca

09/03/2020, 10:33 AM
@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

Matteo Mirk

09/03/2020, 10:42 AM
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

AlexJuca

09/03/2020, 11:30 AM
@Matteo Mirk Thanks, exactly what it is built for. If you have any issues please do leave an issue.
👌 1
m

Matteo Mirk

09/03/2020, 11:35 AM
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 :kotlin: , so maybe someone will find it useful
❤️ 1
a

AlexJuca

09/03/2020, 1:00 PM
@Matteo Mirk Thanks much!
k

kqr

09/03/2020, 1:12 PM
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

AlexJuca

09/03/2020, 1:21 PM
@kqr Thanks for the feedback. I will look for ways to add custom error response representations.
m

Matteo Mirk

09/03/2020, 1:28 PM
@kqr those are nice improvements, maybe submit an issue or pull request to the project
👍 1
k

kqr

09/03/2020, 1:29 PM
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

AlexJuca

09/20/2020, 9:39 PM
Custom error responses have been added. Checkout the changes and tell me you how you feel about this https://github.com/nextbss/requirekt