Javalin: Create Kotlin extension library for Javalin

Created on 24 Mar 2018  路  5Comments  路  Source: tipsy/javalin

There are lots of Kotlin guys that don't like some parts of the syntax Javalin has.
The extension library is just a bunch of different functions to allow more Kotlin-like syntax.

Example from #150 :

Current Kotlin code:

ctx.paramMap()["id"]?.let {
    ...
}

Extension function:

val Context.params: Map<String, String> = this.paramMap()

ctx.params["id"].let { }

The library could be supplied as a separate artifact (eg io.javalin.k-javalin or so) to not bother the Java users.

FEATURE REQUEST HELP WANTED INPUT WANTED

Most helpful comment

I agree, though it is not limited to context params only. Will check if the extensions can improve the syntax more significantly, as I am not sure that Javalin will benefit from these (^^^) extensions a lot.

All 5 comments

A more natural "current vs extension" comparison would be

Path params

ctx.param("id")?.let { ... } // current
ctx.params["id"]?.let { ... } // extension

Query Params

ctx.queryParam("qp")?.let { ... } // current
ctx.queryParams["qp"]?.let { ... } // extension
ctx.queryParams("qp")?.let { ... } // current
ctx.queryParamLists["qp"]?.let { ... } // extension

Query Params (alt)

ctx.queryParam("qp")?.let { ... } // current
ctx.queryParams["qp"].first()?.let { ... } // extension
ctx.queryParams("qp")?.let { ... } // current
ctx.queryParams["qp"]?.let { ... } // extension

I agree, though it is not limited to context params only. Will check if the extensions can improve the syntax more significantly, as I am not sure that Javalin will benefit from these (^^^) extensions a lot.

@ShikaSD have you looked at this yet? Should we keep it open?

We can close it, the only major change affecting syntax could be some dsl in kotlin style. However, I doubt it is required for now, as personally I am fine with the dsl Javalin has with static methods.

Great, I've started thinking that keeping the library consistent across Java and Kotlin is a main goal of the project.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gane5h picture gane5h  路  3Comments

bvicenzo picture bvicenzo  路  3Comments

MFernstrom picture MFernstrom  路  3Comments

FredDeschenes picture FredDeschenes  路  5Comments

maxemann96 picture maxemann96  路  5Comments