ProductPromotion
Logo

Kotlin

made by https://0x3d.site

GitHub - perwendel/spark-kotlin: A Spark DSL in idiomatic kotlin // dependency: com.sparkjava:spark-kotlin:1.0.0-alpha
A Spark DSL in idiomatic kotlin // dependency: com.sparkjava:spark-kotlin:1.0.0-alpha - perwendel/spark-kotlin
Visit Site

GitHub - perwendel/spark-kotlin: A Spark DSL in idiomatic kotlin // dependency: com.sparkjava:spark-kotlin:1.0.0-alpha

GitHub - perwendel/spark-kotlin: A Spark DSL in idiomatic kotlin // dependency: com.sparkjava:spark-kotlin:1.0.0-alpha

spark-kotlin

A Spark DSL in idiomatic kotlin.

Authors:

  • Per Wendel, @perwendel
  • Love Löfdahl, @lallemupp

Dependency:

Maven:

<dependency>
    <groupId>com.sparkjava</groupId>
    <artifactId>spark-kotlin</artifactId>
    <version>1.0.0-alpha</version>
</dependency>

Gradle:

compile "com.sparkjava:spark-kotlin:1.0.0-alpha"

Documentation

Routes

// Static API
get("/hello") {
    "Hello Spark Kotlin"
}

get("/doc") {
    // available (same in instance API)
    params()
    params("<path-param-name>")
    splat()
    status()
    status(404)
    queryParams("<key>")
    queryMap()
    queryMap("<key>")
    attribute("<key>")
    attribute("<key>", "<value>")
    attributes()
    session()
    session(create = true)
    contentType()
    uri()
    protocol()
    scheme()
    host()
    port()
    pathInfo()
    servletPath()
    contextPath()
    userAgent()
    requestMethod()
    type()
    type(contentType = "application/json")
    redirect(location = "/to")
    redirect(location = "/to", statusCode = 302)
    
    // has all above and some more
    request 
    response
}

get("/nothing") {
    status(404)
    "Oops, we couldn't find what you're looking for"
}

get("/saymy/:name") {
    params(":name")
}

get("/redirect") {
    redirect("/hello")
}

// Instance API
val http = ignite()

http.get("/hello") {
    "Hello Spark Kotlin"
}

http.get("/nothing") {
    status(404)
    "Oops, we couldn't find what you're looking for"
}

http.get("/saymy/:name") {
    params(":name")
}

http.get("/redirect") {
    redirect("/hello")
}

Initialization DSL

// Static API
config {
    port = 5500
    ipAddress = "0.0.0.0"
    threadPool {
        maxThreads = 10
        minThreads = 5
        idleTimeoutMillis = 1000
    }
    secure {
        keystore {
            file = "/etc/secure/keystore"
            password = "hardtocrack"
        }
        truststore {
            file = "/etc/secure/truststore"
            password = "otherdifficultpassword"
        }
        needsClientCert = false
    }
    staticFiles {
        location = "/public"
        expiryTime = 36000.seconds
        headers(
                "description" to "static content",
                "licence" to "free to use"
        )
        mimeTypes(
                "cxt" to "text/html"
        )
    }
}

// Instance API
val http = ignite {
    port = 5500
    ipAddress = "0.0.0.0"
    threadPool {
        maxThreads = 10
        minThreads = 5
        idleTimeoutMillis = 1000
    }
    secure {
        keystore {
            file = "/etc/secure/keystore"
            password = "hardtocrack"
        }
        truststore {
            file = "/etc/secure/truststore"
            password = "otherdifficultpassword"
        }
        needsClientCert = false
    }
    staticFiles {
        location = "/public"
        expiryTime = 36000.seconds
        headers(
                "description" to "static content",
                "licence" to "free to use"
        )
        mimeTypes(
                "cxt" to "text/html"
        )
    }
}

Redirect DSL

// Static API
redirect {
    any(
            "/from" to "/hello",
            "/hi" to "/hello"
    )
    get(
            "/source" to "/target"
    )
    post(
            "/gone" to "/new"
    )
}

// Instance API
http.redirect {
    any(
            "/from" to "/hello",
            "/hi" to "/hello"
    )
    get(
            "/source" to "/target"
    )
    post(
            "/gone" to "/new"
    )
}



WebSocket DSL (design ongoing)

// Static API
webSocket("/echo") {
    opened {
        println("[Opened] remote address = " + session.remoteAddress)
    }
    received {
        println("[Received] message = $message")
    }
    closed {
        println("[Closed] code = $code, reason = $reason, session = $session")
    }
    error {
        println("[Error] cause = " + cause)
    }
}

// Instance API
http.webSocket("/echo") {
    opened {
        println("[Opened] remote address = " + session.remoteAddress)
    }
    received {
        println("[Received] message = $message")
    }
    closed {
        println("[Closed] code = $code, reason = $reason, session = $session")
    }
    error {
        println("[Error] cause = " + cause)
    }
}

class WebSocketSession
    val remote
    var idleTimeout
    val isOpen
    val localAddress
    val protocolVersion
    val upgradeResponse
    val upgradeRequest
    val policy
    val isSecure
    val remoteAddress
    
    fun disconnect()
    fun suspend(): Suspension 
    fun close()
    fun close(closeStatus: CloseStatus?)
    fun close(statusCode: Int, reason: String?)
    fun raw(): Session

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory