用Scala实现简单的Web和API服务器( 三 )

package app

object MinimalApplication extends cask.MainRoutes{

@cask.get("/")

defhello= {

"Hello World!"

}

@cask.post("/do-thing")

defdoThing(request:cask.Request)= {

new String(request.readAllBytes).reverse

}

initialize

}

用build.sc进行构建:

import mill._, scalalib._

object app extends ScalaModule{

defscalaVersion= "2.13.0"

defivyDeps= Agg(

ivy"com.lihaoyi::cask:0.3.0"

推荐阅读