Skip to content

micro web framework like Pippo and written in Kotlin

Notifications You must be signed in to change notification settings

ScienJus/konata

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Konata

micro web framework like decebals/pippo and written in Kotlin

Route DSL

Konata uses nikic/FastRoute and has a simple DSL to configure routes. like:

fun main(args: Array<String>) {
    konata {
    
        // higher-order functions, (Request, Response) -> Unit
        get("/", { req, res ->
            res.send("home")
        })

        // route groups
        group("/users") {
            get(":id", { req, res ->
                res.send("user(id=${req.getPathVariable("id")})")
            })

            group("posts") {
                get(":id", { req, res ->
                    res.send("post(id=${req.getPathVariable("id")})")
                })
            }
        }
        
        // anonymous functions is not supported yet :(
        get("/tags/:name", fun (name: String): String {
            return "tag(name=$name)"
        })
        
        // but you can use local functions
        get("/tags/:name", ::showTag)
        
        // or member functions
        get("/tags/:name", TagController::show)
        
        class TagController {

            fun show(name: String): String {
                return "tag(name=$name)"
            }
        }
    }.start()
}

fun showTag(name: String): String {
    return "tag(name=$name)"
}

About

micro web framework like Pippo and written in Kotlin

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages