{"id":13428539,"url":"https://github.com/perwendel/spark-kotlin","last_synced_at":"2025-04-08T16:07:34.853Z","repository":{"id":57728331,"uuid":"92269915","full_name":"perwendel/spark-kotlin","owner":"perwendel","description":"A Spark DSL in idiomatic kotlin // dependency: com.sparkjava:spark-kotlin:1.0.0-alpha","archived":false,"fork":false,"pushed_at":"2020-03-14T17:07:14.000Z","size":118,"stargazers_count":988,"open_issues_count":21,"forks_count":43,"subscribers_count":34,"default_branch":"master","last_synced_at":"2025-04-01T15:09:55.965Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/perwendel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-24T08:39:20.000Z","updated_at":"2025-02-11T10:10:43.000Z","dependencies_parsed_at":"2022-09-26T22:00:54.397Z","dependency_job_id":null,"html_url":"https://github.com/perwendel/spark-kotlin","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/perwendel%2Fspark-kotlin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/perwendel%2Fspark-kotlin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/perwendel%2Fspark-kotlin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/perwendel%2Fspark-kotlin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/perwendel","download_url":"https://codeload.github.com/perwendel/spark-kotlin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247878022,"owners_count":21011158,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T01:01:00.004Z","updated_at":"2025-04-08T16:07:34.826Z","avatar_url":"https://github.com/perwendel.png","language":"Kotlin","funding_links":[],"categories":["Libraries","Kotlin"],"sub_categories":[],"readme":"# spark-kotlin\n\nA Spark DSL in idiomatic kotlin.\n\nAuthors:\n--------\n- Per Wendel, @perwendel\n- Love Löfdahl, @lallemupp\n\nDependency:\n-----------\nMaven:\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.sparkjava\u003c/groupId\u003e\n    \u003cartifactId\u003espark-kotlin\u003c/artifactId\u003e\n    \u003cversion\u003e1.0.0-alpha\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nGradle:\n```groovy\ncompile \"com.sparkjava:spark-kotlin:1.0.0-alpha\"\n```\n\nDocumentation\n-------------\n\nRoutes\n------\n\n```kotlin\n// Static API\nget(\"/hello\") {\n    \"Hello Spark Kotlin\"\n}\n\nget(\"/doc\") {\n    // available (same in instance API)\n    params()\n    params(\"\u003cpath-param-name\u003e\")\n    splat()\n    status()\n    status(404)\n    queryParams(\"\u003ckey\u003e\")\n    queryMap()\n    queryMap(\"\u003ckey\u003e\")\n    attribute(\"\u003ckey\u003e\")\n    attribute(\"\u003ckey\u003e\", \"\u003cvalue\u003e\")\n    attributes()\n    session()\n    session(create = true)\n    contentType()\n    uri()\n    protocol()\n    scheme()\n    host()\n    port()\n    pathInfo()\n    servletPath()\n    contextPath()\n    userAgent()\n    requestMethod()\n    type()\n    type(contentType = \"application/json\")\n    redirect(location = \"/to\")\n    redirect(location = \"/to\", statusCode = 302)\n    \n    // has all above and some more\n    request \n    response\n}\n\nget(\"/nothing\") {\n    status(404)\n    \"Oops, we couldn't find what you're looking for\"\n}\n\nget(\"/saymy/:name\") {\n    params(\":name\")\n}\n\nget(\"/redirect\") {\n    redirect(\"/hello\")\n}\n\n// Instance API\nval http = ignite()\n\nhttp.get(\"/hello\") {\n    \"Hello Spark Kotlin\"\n}\n\nhttp.get(\"/nothing\") {\n    status(404)\n    \"Oops, we couldn't find what you're looking for\"\n}\n\nhttp.get(\"/saymy/:name\") {\n    params(\":name\")\n}\n\nhttp.get(\"/redirect\") {\n    redirect(\"/hello\")\n}\n```\nInitialization DSL\n------------------\n```kotlin\n// Static API\nconfig {\n    port = 5500\n    ipAddress = \"0.0.0.0\"\n    threadPool {\n        maxThreads = 10\n        minThreads = 5\n        idleTimeoutMillis = 1000\n    }\n    secure {\n        keystore {\n            file = \"/etc/secure/keystore\"\n            password = \"hardtocrack\"\n        }\n        truststore {\n            file = \"/etc/secure/truststore\"\n            password = \"otherdifficultpassword\"\n        }\n        needsClientCert = false\n    }\n    staticFiles {\n        location = \"/public\"\n        expiryTime = 36000.seconds\n        headers(\n                \"description\" to \"static content\",\n                \"licence\" to \"free to use\"\n        )\n        mimeTypes(\n                \"cxt\" to \"text/html\"\n        )\n    }\n}\n\n// Instance API\nval http = ignite {\n    port = 5500\n    ipAddress = \"0.0.0.0\"\n    threadPool {\n        maxThreads = 10\n        minThreads = 5\n        idleTimeoutMillis = 1000\n    }\n    secure {\n        keystore {\n            file = \"/etc/secure/keystore\"\n            password = \"hardtocrack\"\n        }\n        truststore {\n            file = \"/etc/secure/truststore\"\n            password = \"otherdifficultpassword\"\n        }\n        needsClientCert = false\n    }\n    staticFiles {\n        location = \"/public\"\n        expiryTime = 36000.seconds\n        headers(\n                \"description\" to \"static content\",\n                \"licence\" to \"free to use\"\n        )\n        mimeTypes(\n                \"cxt\" to \"text/html\"\n        )\n    }\n}\n```\nRedirect DSL\n------------\n```kotlin\n// Static API\nredirect {\n    any(\n            \"/from\" to \"/hello\",\n            \"/hi\" to \"/hello\"\n    )\n    get(\n            \"/source\" to \"/target\"\n    )\n    post(\n            \"/gone\" to \"/new\"\n    )\n}\n\n// Instance API\nhttp.redirect {\n    any(\n            \"/from\" to \"/hello\",\n            \"/hi\" to \"/hello\"\n    )\n    get(\n            \"/source\" to \"/target\"\n    )\n    post(\n            \"/gone\" to \"/new\"\n    )\n}\n\n\n\n```\nWebSocket DSL (design ongoing)\n------------------------------\n```kotlin\n// Static API\nwebSocket(\"/echo\") {\n    opened {\n        println(\"[Opened] remote address = \" + session.remoteAddress)\n    }\n    received {\n        println(\"[Received] message = $message\")\n    }\n    closed {\n        println(\"[Closed] code = $code, reason = $reason, session = $session\")\n    }\n    error {\n        println(\"[Error] cause = \" + cause)\n    }\n}\n\n// Instance API\nhttp.webSocket(\"/echo\") {\n    opened {\n        println(\"[Opened] remote address = \" + session.remoteAddress)\n    }\n    received {\n        println(\"[Received] message = $message\")\n    }\n    closed {\n        println(\"[Closed] code = $code, reason = $reason, session = $session\")\n    }\n    error {\n        println(\"[Error] cause = \" + cause)\n    }\n}\n\nclass WebSocketSession\n    val remote\n    var idleTimeout\n    val isOpen\n    val localAddress\n    val protocolVersion\n    val upgradeResponse\n    val upgradeRequest\n    val policy\n    val isSecure\n    val remoteAddress\n    \n    fun disconnect()\n    fun suspend(): Suspension \n    fun close()\n    fun close(closeStatus: CloseStatus?)\n    fun close(statusCode: Int, reason: String?)\n    fun raw(): Session\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fperwendel%2Fspark-kotlin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fperwendel%2Fspark-kotlin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fperwendel%2Fspark-kotlin/lists"}