Last active
August 28, 2017 08:03
-
-
Save daviddenton/845c2490c9158c7b91c5f8f97ec7cf97 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// add this method, and verb variants to ApiBuilder... | |
public static void get(String path, Function<Javalin, Handler> fn) { | |
staticInstance().get(prefixPath(path), fn.apply(staticInstance())); | |
} | |
// then you can remove the extra methods from ApiBuilder and Javalin which take the overloads |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val myHandler = Handler { it.status(200) } | |
// this extension function will fix the readability problem IMHO, and add the security behaviour that you want. | |
fun Handler.securedBy(vararg roles: Role): (Javalin) -> Handler = | |
{ j -> Handler { ctx -> j.accessManager.manage(this, ctx, roles.toList()) } } | |
val whatever = path("users") { | |
get("/foo", myHandler.securedBy(ApiRole.ANYONE, ApiRole.USER_READ)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment