From d44a6a545d5233808fb02f551ef2b415b4d65cad Mon Sep 17 00:00:00 2001 From: efim Date: Sun, 25 Jun 2023 14:49:55 +0000 Subject: [PATCH] feat: adding simplest cask routes --- scala-cli-cask-attempt/.scalafmt.conf | 2 ++ scala-cli-cask-attempt/Readme.org | 14 ++++++++++ .../src/main/scala/app/Main.scala | 27 +++++++------------ 3 files changed, 25 insertions(+), 18 deletions(-) create mode 100644 scala-cli-cask-attempt/.scalafmt.conf diff --git a/scala-cli-cask-attempt/.scalafmt.conf b/scala-cli-cask-attempt/.scalafmt.conf new file mode 100644 index 0000000..db004c6 --- /dev/null +++ b/scala-cli-cask-attempt/.scalafmt.conf @@ -0,0 +1,2 @@ +version = "3.7.3" +runner.dialect = scala3 \ No newline at end of file diff --git a/scala-cli-cask-attempt/Readme.org b/scala-cli-cask-attempt/Readme.org index 954e863..596deec 100644 --- a/scala-cli-cask-attempt/Readme.org +++ b/scala-cli-cask-attempt/Readme.org @@ -8,3 +8,17 @@ this should be on the very top of the file, otherwise it's not visible to scala-cli that was my error for a while - having package declaration on top +** replicating simplest cask example +https://github.com/com-lihaoyi/cask/blob/master/example/minimalApplication/app/src/MinimalApplication.scala +*** and it works! +opening localhost:8080 shows "Hello world!" + +and opening Network tab, refreshing to see get request, +and doing "Edit and Resend" to issue Post to /do-thing with some text in body +returns the result with test reversed. + +this is really nice. +** what i'd really like though is browser refresh. +i suppose that can be added to emacs? also on file save :shrug: somehow +** for the future - more details on things of cask +https://com-lihaoyi.github.io/cask/index.html#minimal-example diff --git a/scala-cli-cask-attempt/src/main/scala/app/Main.scala b/scala-cli-cask-attempt/src/main/scala/app/Main.scala index 3a008b7..f820423 100644 --- a/scala-cli-cask-attempt/src/main/scala/app/Main.scala +++ b/scala-cli-cask-attempt/src/main/scala/app/Main.scala @@ -6,26 +6,17 @@ // import munit.FunSuite package app -object Main { - def main(args: Array[String]) = { - final case class Thingy(a: String, b: Int, c: List[Double]) - val th = Thingy("hello", 1234, List(1D, 1.523, 1234.1234)) - pprint.pprintln(th) - println(th) +object Main extends cask.MainRoutes { + @cask.get("/") + def hello() = { + "Hello world!" } - // object MinimalExample extends cask.MainRoutes { - // @cask.get("/") - // def hello() = { - // "Hello world!" - // } + @cask.post("/do-thing") + def doThing(request: cask.Request) = { + request.text().reverse + } - // @cask.post("/do-thing") - // def doThing(request: cask.Request) = { - // request.text().reverse - // } - - // initialize() - // } + initialize() }