ruby 中最简单的 servlet 库是什么?
您推荐使用什么框架在 ruby 中编写简单的 Web 应用程序,介于 WebRick、< a href="http://mongrel.rubyforge.org/" rel="nofollow">Mongrel 和 西纳特拉?
我想以 json 格式回答客户端的请求。我希望自己的代码尽可能与 Http 框架解耦。
你还知道其他框架吗?
What framework do you recommand for writing simple web applications in ruby, between WebRick, Mongrel and Sinatra ?
I would like to answer in json to requests from a client. I would like to have my own code decoupled from the Http framework as much as possible.
Do you know any other framework ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不建议使用 WEBrick,就这样。与 Rack 兼容的框架将为您提供最好的服务。为了提高速度,您可以直接在 Rack 中编写,但这确实没有必要,因为 Sinatra 更令人愉快并且仍然非常快。
您可能还想查看 Halcyon。我不知道它是否仍在维护,但它是为编写以 JSON 响应的 API 而设计的。
I wouldn't recommend using WEBrick, period. You would best be served by a Rack-compatible framework. You could write directly in Rack for speed, but it's really unnecessary since Sinatra is so much more pleasant and still very fast.
You may also want to check out Halcyon. I don't know if it's still maintained, but it's designed for writing APIs that respond in JSON.
WEBrick 和 Mongrel 是服务器,而不是用于构建 Web 应用程序的框架。因此,它们具有较低级别的 API,并且与它们自己的特性相关联,这使得如果您想要设计 Web 应用程序以便它可以在不同的服务器上运行,那么它们是一个不好的起点。
我会寻找一个基于 Rack 构建的框架,这是构建 Web 应用程序和 Web 框架的标准基础层这些天在 Ruby 中。
如果您正在制作非常简单的东西,那么学习 Rack 的界面本身就是一个很好的起点。
EG,一个机架应用程序,它从 post 请求的正文中解析 json 并将其打印回来并进行美化。
您可以通过在与该文件相同的目录中运行
rackup
来运行它。或者,如果你想要更高层次的东西,你可以使用 sinatra,看起来
Sinatra 的 README 是一个很好的介绍其特点。
WEBrick and Mongrel are servers, not frameworks for building web applications. As such, they have APIs that are lower level and tied to their own idiosyncrasies which makes them a bad place to start if you want to design your web application so that it can run on different servers.
I would look for a framework that builds on Rack, which is the standard base layer for building web apps and web frameworks in Ruby these days.
If you are making something really simple, learning Rack's interface by itself is a good place to start.
E.G., a Rack Application that parses json out of a post request's body and prints it back out prettified.
you can run it by running
rackup
in the same dir as the file.Or, if you want something a bit more high level, you can use sinatra, which looks like this
Sinatra's README is a good introduction to it's features.