Loft Server单线程 HTTP 服务器
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
}
}
评论