剩余 API 服务器的 Scala 框架? ?

我们正在考虑将我们的 RestAPI 服务器(它位于 Symfony PHP 的 Web 服务内部)迁移到 Scala,原因有几个: 速度快、无开销、更少的 CPU、更少的代码、可伸缩性等等。我直到几天前才知道 Scala,但是我很享受这些天通过 Scala 的书以及所有的博客文章和问题学到的东西(它并没有那么丑!)

我有以下选择:

  • 从零开始构建剩余 API 服务器
  • 使用像 斯卡拉特拉这样的微型 Scala web 框架
  • 使用升降机

我将不得不使用的一些东西: HTTP 请求、 JSON 输出、 MySQL (数据)、 OAuth、 Memcache (缓存)、日志、文件上传、 Stats (也许是 Redis)。

你有什么建议吗?

74086 次浏览

I'm going to recommend Unfiltered. It's an idiomatic Web framework that does things "the Scala way" and is very beautiful.

I would add two more options: akka with built-in JAX-RS support, and simply using JAX-RS directly (probably the Jersey implementation). While arguably less "Scala-y" than others (relying upon annotations to bind parameters and paths), JAX-RS is a joy to use, cleanly solving all of the problems of web service coding with minimal footprint. I've not used it via akka, I would anticipate it being excellent there, getting impressive scalability via it's continuation-based implementation.

In no particular order:

All good answers so far. One point in Lift's favor is its RestHelper, which can make it quite easy to write short, elegant API methods. In addition, all the other things you want to do should be quite straight-forward to implement in Lift. That being said, Memcache might be not be necessary.

Take a look at Xitrum (I'm its author), it provides everything you listed. Its doc is quite extensive. From README:

Xitrum is an async and clustered Scala web framework and web server on top of Netty and Hazelcast:

  • Annotation is used for URL routes, in the spirit of JAX-RS. You don't have to declare all routes in a single place.
  • Async, in the spirit of Netty.
  • Sessions can be stored in cookies or clustered Hazelcast.
  • In-process and clustered cache, you don't need separate cache servers.
  • In-process and clustered Comet, you don't need a separate Comet server.

A little late on the scene but I would definitely recommend using Bowler framework for creation of REST API's. It small, to the point and automatic case class conversion support!

Take a look at Finch, a Scala combinator library for building Finagle HTTP services. Finch allows you to construct complex HTTP endpoints out of the number of predefined basic blocks. Similarly to parser combinators, Finch endpoints are easy to reuse, compose, test, and reason about.