用于 Rest API 服务器的 Scala 框架?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3678795/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 02:25:16  来源:igfitidea点击:

Scala framework for a Rest API Server?

apirestscalalift

提问by fesja

We are thinking on moving our Rest API Server (it is inside the web service, on Symfony PHP) to Scala for several reasons: speed, no overhead, less CPU, less code, scalability, etc. I didn't know Scala until several days ago but I've been enjoying what I've been learning these days with the Scala book and all the blog posts and questions (it's not so ugly!)

我们正在考虑将我们的 Rest API 服务器(它在 Web 服务内部,在 Symfony PHP 上)迁移到 Scala,原因有几个:速度、无开销、更少的 CPU、更少的代码、可扩展性等。直到几个我才知道 Scala几天前,但我一直很享受这些天我在 Scala 书和所有博客文章和问题中学到的东西(它不是那么难看!)

I have the following options:

我有以下选择:

  • build the Rest API Server from scratch
  • use a tiny Scala web framework like Scalatra
  • use Lift
  • 从头开始构建 Rest API Server
  • 使用像Scalatra这样的小型 Scala Web 框架
  • 使用电梯

Some things that I will have to use: HTTP requests, JSON output, MySQL (data), OAuth, Memcache (cache), Logs, File uploads, Stats (maybe Redis).

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

What would you recommend?

你会推荐什么?

采纳答案by oluies

In no particular order:

没有特定的顺序:

回答by Max A.

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

我要推荐Unfiltered。它是一个惯用的 Web 框架,以“Scala 方式”做事并且非常漂亮。

回答by Ngoc Dao

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

看看Xitrum(我是它的作者),它提供了您列出的所有内容。它的文档非常广泛。从自述文件:

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

Xitrum 是一个基于 Netty 和 Hazelcast 的异步和集群 Scala Web 框架和 Web 服务器:

  • 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.
  • 本着 JAX-RS 的精神,注解用于 URL 路由。您不必在一个地方声明所有路由。
  • 异步,本着 Netty 的精神。
  • 会话可以存储在 cookie 或集群 Hazelcast 中。
  • 进程内缓存和集群缓存,您不需要单独的缓存服务器。
  • 进程内和集群 Comet,您不需要单独的 Comet 服务器。

回答by Dave Griffith

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.

我还要添加两个选项:带有内置 JAX-RS 支持的 akka,以及直接使用 JAX-RS(可能是 Jersey 实现)。虽然可以说比其他人更少“Scala-y”(依靠注释来绑定参数和路径),但 JAX-RS 使用起来很愉快,以最小的占用空间干净地解决了 Web 服务编码的所有问题。我没有通过 akka 使用过它,我预计它在那里非常出色,通过它基于延续的实现获得了令人印象深刻的可扩展性。

回答by Vladimir Kostyukov

Take a look at Finch, a Scala combinator library for building FinagleHTTP 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.

看看Finch,这是一个用于构建FinagleHTTP 服务的 Scala 组合器库。Finch 允许您从预定义的基本块数量中构建复杂的 HTTP 端点。与解析器组合器类似,Finch 端点易于重用、组合、测试和推理。

回答by pr1001

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.

到目前为止所有好的答案。Lift 的优点之一是它的RestHelper,它可以使编写简短、优雅的 API 方法变得非常容易。此外,您想要做的所有其他事情在 Lift 中都应该非常直接。话虽如此,Memcache 可能不是必需的。

回答by cracked_all

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

现场有点晚了,但我绝对建议使用Bowler框架来创建 REST API。它小巧、中肯和自动案例类转换支持!