Loft Server单线程 HTTP 服务器

联合创作 · 2023-10-01 13:59

loft 是一个用 Scala 开发的单线程 HTTP 服务器,示例代码如下:

object ExampleHandler extends RequestHandler {

  @Asynchronous
  def get() {
    val http = AsyncHTTPClient()
    reset {
      val id = redis get("roger_schildmeijer");   //async call
      val result = http fetch("http://127.0.0.1:8080/" + id); //async call
      write(result)
      finish 
    }
  }

  val application = Application(Map("/".r -> this))

  def main(args: Array[String]) {
    val httpServer = HTTPServer(application)
    httpServer listen(8888)
    IOLoop start
  }

}
浏览 8
点赞
评论
收藏
分享

手机扫一扫分享

编辑 分享
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

编辑 分享
举报