<@U3W8YSSSV> The extension property concept is int...
# server
d
@tipsy The extension property concept is interesting - not really seen that done before ๐Ÿ™‚ After a brief look, a couple of things spring out: 1. The ApiBuilder class now has 4 methods for each HTTP verb - one for various combinations of the path/Handler/Role list. This seems like as a possible problem going forward - eg. will the next concept introduced into the API builder result in 8 methods per HTTP verb? If you could find a way to combine the behavioural changes into a decorated implementation of the Handler interface then the ApiBuilder contract could stay simple. so maybe you'd call
get(roles(UserController::getAllUserIds, ApiRole.ANYONE))
instead - where the
roles()
method returns another Handler. 2. There's a type in your tutorial - should
this.header("Basic")
be
this.header("Authorization")
?
t
first, thanks for going through the tutorial (and my source!)
The extension property concept is interesting - not really seen that done before
yeah, i like it a lot, i try to use it everywhere it makes sense
will the next concept introduced into the API builder result in 8 methods per HTTP verb?
yup. it's not ideal, but i'm willing to write this boilerplate if it leads to a nicer api for end-users.
get(controller, roles(...))
reads a lot better than
get(roles(controller, ...))
, in my opinion. at a certain point i guess it will become too much, but i don't think there are a lot more concepts to add
should
this.header("Basic")
be
this.header("Authorization")
thanks, fixed. that's what i get for writing the tutorial before actually creating a project and running the code ๐Ÿ™ƒ
d
Well the readability can be fixed by converting it to an extension function, so you'd get something like
Copy code
handler.securedBy(Role.God, Role.Minion)
At the moment, there are duplicate methods on ApiBuilder and Javalin which take the roles et al. By replacing them with a single method (for each verb), we can then use a callback onto Javalin to add behaviour without ever touching the ApiBuilder again: https://gist.github.com/daviddenton/845c2490c9158c7b91c5f8f97ec7cf97
I think that should work.. but it's always possible that it won't ๐Ÿ™‚
let me know if it's not clear (I often am not) ๐Ÿ™‚
t
that looks a lot nicer
i've made an issue to look into it
thanks
d
np ๐Ÿ™‚
t
this is more advanced kotlin than i'm comfortable with. i would need this syntax
Controller::action.securedBy(...)
to work too, which i'm not sure looks very nice anymore either way there's no way to make this work in java (?)
d
1 question I'd ask - are you really worried about people accessing your APIs from Java? We asked the same question of http4k, and decided that if people want to use java then there are hundred other web libraries they'd use before us. Also, they'd have to be introducing the entire kotlin language to their app just to use a web library - which is a bit odd when you think about it. Just my 2c... ๐Ÿ™‚
t
1 question I'd ask - are you really worried about people accessing your APIs from Java?
yes. i'm a primarily a java (/frontend) dev working in a company that only does java.. great java interop is a goal for me, and it helps me learn the language.
Also, they'd have to be introducing the entire kotlin language to their app just to use a web library - which is a bit odd when you think about it. Just my 2c... ๐Ÿ™‚
you don't need to have kotlin installed to use a jar that was built with kotlin