简体   繁体   English

使用Ruby / Sinatra和JRuby或Scala构建REST API

[英]Building a REST API with Ruby/Sinatra and JRuby or Scala

I'm building a new REST API that will replace a pre-existing one. 我正在构建一个新的REST API,它将取代现有的REST API。 The older API was written to be a SOAP API built with Java and this is where the questions resides. 较旧的API被编写为使用Java构建的SOAP API,这就是问题所在。 Most of the data access layer libraries are written in Java and if we could use those libraries would be a great asset. 大多数数据访问层库都是用Java编写的,如果我们可以使用这些库将是一个很好的资产。

Our two options so far are: Ruby/Sinatra and Scala/Lift 到目前为止,我们的两个选项是: Ruby / SinatraScala / Lift

We also have the possibility to use JRuby on the Ruby/Sinatra stack in order to use the Java libraries that I mentioned before. 我们还可以在Ruby / Sinatra堆栈上使用JRuby ,以便使用我之前提到的Java库。 Our main worry is in regards to possible JRuby-Java libraries incompatibilities... 我们主要担心的是可能的JRuby-Java库不兼容......

What do you reckon is the best approach? 您认为最好的方法是什么?

If you're looking at Ruby/Sinatra you might want to consider Scala/Scalatra instead of lift as they are pretty similar. 如果您正在查看Ruby / Sinatra,您可能需要考虑Scala / Scalatra而不是lift,因为它们非常相似。 The advantage of scala here would be a really really great java interoperability Another scala option to consider is Finagle (my favorite) as it is field proven and geared towards hosting services (vs. web pages) 这里scala的优势是非常好的java互操作性另一个需要考虑的scala选项是Finagle (我最喜欢的),因为它经过现场验证并适用于托管服务(与网页相对)

I've been using Ruby for the past 2 years, and recently tried to develop an application using Scala & Lift. 我在过去的两年里一直在使用Ruby,最近尝试使用Scala&Lift开发应用程序。

I gave up on Scala in favor of Ruby, and here's why. 我放弃了Scala,支持Ruby,这就是原因。

The Ruby community is huge compared to Lift, you can get a gem basically for everything, there's tons of documentation and tutorials and it's easy to get a fast response when you run into trouble. 与Lift相比,Ruby社区是巨大的,你可以为所有东西获得一个宝石,有大量的文档和教程,当你遇到麻烦时很容易获得快速响应。 The Lift tag here on SO has only about 500 questions. SO上的Lift标签只有大约500个问题。

Lift has a completely different approach to stuff , and unless you already know Scala, it will give you a lot of pain before you get the hang of it. Lift有一个完全不同的方法 ,除非你已经知道Scala,否则在你掌握它之前会给你带来很多痛苦。

On the other hand, Sinatra is dead simple and obvious. 另一方面, Sinatra死得简单明了 It's easy to integrate with other rack-based libraries and there's just tons of documentation and tutorials on Sinatra related issues. 它很容易与其他基于机架的库集成,并且有大量关于Sinatra相关问题的文档和教程。

I don't want to sound like I think Lift is bad, but it's definitely a lot more complicated to start with. 我不想听起来像我认为Lift很糟糕,但开始时肯定要复杂得多。 Prototyping with Sinatra is also insanely easy, since you can drop everything into one file. 使用Sinatra进行原型设计也非常简单,因为您可以将所有内容放入一个文件中。 Lift is a lot more heavyweight. 电梯是更重量级的。

All this comes down is a matter of preferrence. 所有这一切都归结为优先考虑。 If you're not afraid of Scala, give Lift a try. 如果您不害怕Scala,请试试Lift。 But if you just want to get the stuff done, Sinatra will give you much less headaches. 但如果你只是想完成这些工作,那么Sinatra会给你带来更少的麻烦。

Seems that you already picked an answer but just my 2 cents: If you do want to try Lift, there is a lift REST example on the wiki , another on the Simply Lift book . 似乎你已经选择了答案,但只是我的2美分:如果你想尝试Lift, 维基上有一个电梯REST示例,另一个是Simply Lift书

A more involved example that uses REST but also has a Comet based front end can be found on this blog post (disclaimer: I wrote that post) 在这篇博客文章中可以找到一个使用REST但也有基于Comet的前端的更复杂的例子(免责声明:我写了这篇文章)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM