一个简单的 Scala Web 框架?

发布于 2024-11-29 13:31:36 字数 332 浏览 1 评论 0原文

有没有简单的 Scala Web 框架?我基本上需要基本功能,例如:

  • 路由。
  • GET/POST/PUT 参数处理。
  • 一个简单模板引擎(基于内容替换)。
  • 序列化(JSON、YAML)

我不喜欢 Lift,因为它对我来说太多了,因为我希望完全控制生成的 HTML,这意味着我希望能够编写 100% 的 HTML/CSS/JS 代码。

有这样的框架吗?或者是否可以以在幕后生成 HTML 的方式使用 Lift?或者我写一个普通的 servlet 会更好吗?

Is there a bare-bones Scala web framework? I basically need the essential features such as:

  • Routing.
  • GET/POST/PUT parameter handling.
  • A simple templating engine (content substitution based).
  • Serialization (JSON, YAML)

I don't like Lift as it does too much for me, as I would like complete control over the generated HTML, meaning that I want to be able to write 100% of the HTML/CSS/JS code.

Is there such a framework? Or is it possible to use Lift in a way that no HTML is generated behind the scenes? Or would I be better of writing a normal servlet?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

可是我不能没有你 2024-12-06 13:31:36

也许您想要类似 Scalatra未过滤?另外,如果您不愿意,则无​​需放弃 Lift 应用程序中对 HTML/CSS/JS 的任何控制。

Perhaps you'd like something like Scalatra or Unfiltered? On a separate note, you need not give up any control of your HTML/CSS/JS in a Lift app if you don't want to.

梦在夏天 2024-12-06 13:31:36

您可以只使用 Lift 来生成服务,例如 REST 服务,这或多或少是您想要的吗? http://www.assembla.com/spaces/liftweb/wiki/REST_Web_Services

如果我们看一下什么Scala Web 框架可用吗? 它们都没有一个很棒的简单模板引擎,至少对我来说是这样。 SweetScala 似乎是最接近的 http://code.google.com/p/sweetscala/wiki /入门

You can just use Lift to generate services, such as REST ones, is that more or less what you are looking for? http://www.assembla.com/spaces/liftweb/wiki/REST_Web_Services

If we take a look at What Scala web-frameworks are available? none of them have a great simple templating engine, at least to me it seems that way. SweetScala seems the closest though http://code.google.com/p/sweetscala/wiki/GettingStarted

少年亿悲伤 2024-12-06 13:31:36

彼得给出了一个很好的答案......我将对此进行一些扩展。

Lift 为您提供对原始 HTTP 请求的大量控制和访问,并在 HTTP 级别之上提供大量抽象。您可以选择希望 Lift 做多少事情。

您可以使用 Lift 的 RestHelper 构建基于 REST 的应用程序。请参阅http://simply.liftweb.net/index-Chapter-5.html 与大多数基于 MVC/路由的方法相比,Lift 的 RestHelper 的优势在于应用程序边缘的类型安全和访问控制。但是使用 Scala 的模式匹配提取器,您可以确保传递到应用程序业务逻辑的参数已经具体化并检查了访问控制。此外,Lift 的 REST 支持将与其他 Web 框架一样简洁或更简洁。

就 Lift 的 HTML 处理而言,只要您希望将 HTML 生成为有效的 DOM 而不是一系列字符串,您就可以对 HTML 的创建进行大量控制。

大多数 Web 框架会强制您在编写 HTML 时发出字符串。开发人员需要正确地对字符串进行 HTML 转义。开发人员有责任确保结束标签正确排列。有了Lift,你就可以免费得到这样的东西。

您可以以 MVC 风格从 Lift 应用程序提供 HTML。请参阅 https://github.com/dpp/hoisted (这是支持http://liftweb.net)

在 Lift 应用程序的“标准”配置中,Lift 会对 HTML 进行一些后处理,当且仅当如果,你使用某种结构。因此,如果您在 HTML 页面正文中放置 标记,Lift 将获取该 标记的内容并将其移动到页面的头部部分。如果您包含对 Lift 的 Comet 支持的调用,Lift 将在页面上插入 JavaScript 来执行长轮询。但这些功能是可选的,只有在您使用 Lift 中的某些功能时才会发生。

我希望这可以帮助您了解使用 Lift 的好处。

Peter gave a great answer... I'll expand on it a little.

Lift gives you a ton of control and access to raw HTTP requests as well as providing a ton of abstractions on top of the HTTP level. It's your choice on how much or how little you want Lift to do.

You can built a REST-based application using Lift's RestHelper. See http://simply.liftweb.net/index-Chapter-5.html The advantage that Lift's RestHelper gives you over most MVC/Routing based approaches is type-safety and access control at the very edge of your application. But using Scala's pattern matching extractors, you can insure that parameters delivered to the business logic of your application have already been materialized and checked for access control. Further, Lift's REST support will be as concise or more concise than other web frameworks.

In terms of Lift's HTML handling, you have a ton of control over the creation of the HTML, as long as you want to generate HTML as a valid DOM rather than as a series of Strings.

Most web frameworks force you to emit Strings when you're composing HTML. It's up to the developer to properly HTML-escape Strings. It's up to the developer to make sure that closing tags line up correctly. With Lift, you get this kind of thing for free.

You can serve HTML from Lift apps in MVC style. See https://github.com/dpp/hoisted (this is the code that powers http://liftweb.net)

In the "standard" configuration of Lift apps, Lift does some post-processing of the HTML if, and only if, you use certain construct. So, if you put a <head> tag in the body, the HTML page, Lift will take the contents of that <head> tag and move it to the head section of the page. If you include calls to Lift's Comet support, Lift will insert JavaScript on the page to do long polling. But these features are optional and they only happen if you use certain features in Lift.

I hope this helps you understand the benefits of using Lift.

无声无音无过去 2024-12-06 13:31:36

另外两个框架供您考虑:

  • Play 是一个简单的 REST 框架,越来越受欢迎,并且有一个很好的 Scala界面。它的模板相对简单地转换为 Scala 函数。几个月前,使用 JSON 包(如 lift-json)将数据解压到案例类中时遇到了困难,因为 Play 有一个用于快速开发的自定义类加载器。不确定这个问题是否得到解决。 Scala 公司 Typesafe 在其网站中使用 Play。 Play 与 Akka 集成,Akka 的首席开发人员之一 Viktor Klang 不久前推荐了 Play。

  • 稍微偏僻一点的地方是Spray。我无法透露细节,但 Wiki 看起来很有趣。在我看来,Spray 看起来是围绕 Akka 集成进行优雅设计的。我不认为它带有模板引擎,但它可能可以与 Scalate 交互(请参阅邮件列表讨论)。

Two more frameworks for you to consider:

  • Play is a simple REST framework that is gaining in popularity, and has a nice Scala interface. Its templates translate relatively simply into Scala functions. As of a couple months ago there were difficulties with using JSON packages (like lift-json) that unpack data into case classes because Play has a custom classloader for rapid development. Not sure if this issue is resolved. The Scala company Typesafe uses Play for their site. Play integrates with Akka, and one of the Akka lead developers, Viktor Klang, recommended Play a while back.

  • A little further off the beaten track, there is Spray. I can't speak to the details, but the Wiki looks intriguing. To my eyes, Spray looks to be elegantly designed around Akka integration. I don't think it comes with a templating engine, but it would probably be possible to interface with Scalate (see the mailing list discussion).

挽清梦 2024-12-06 13:31:36

本身不是 Scala 框架,但我很幸运地使用了 Jetty+JAX-RS+Scala+Freemarker。这些都是经过严格考验的技术,并且与 Scala 集成没有任何问题。需要一个小垫片才能使 Freemarker 理解 Scala 集合和属性,但这没什么挑战性。

Not a Scala framework per-se, but I've had good luck with Jetty+JAX-RS+Scala+Freemarker. These are all pretty heavily battle-tested technologies, and there's no problems with Scala integration. A small shim is necessary to adapt Freemarker to understand Scala collections and properties, but nothing challenging.

旧情别恋 2024-12-06 13:31:36

Scalatra 非常简单,具有 scala 的优点。易于配置,易于处理 Bare HTTP 内容。它类似于scala的sinatra。
Scalatra 还具有良好的 Maven 支持,并且与传统的 java servlet 能够很好地共存。

Scalatra is pretty bare bones with the scala goodness. Easy to configure, easy to handle Bare HTTP stuff. It is similar to sinatra of scala.
Scalatra also has good Maven support and coexists well with traditional java servlets.

素染倾城色 2024-12-06 13:31:36

现代 Scala Web 框架有:Play(在 Akka HTTP 上)、Scalatra(Akka Actors)和 Finatra。
https://www.reddit.com/r/scala/comments/743zjv /web_framework/

The modern Scala web framework are: Play (on Akka HTTP), Scalatra (Akka Actors) and Finatra.
https://www.reddit.com/r/scala/comments/743zjv/web_framework/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文