如何选择完美的REST风格的框架? [英] How to choose the perfect RESTful framework?

查看:80
本文介绍了如何选择完美的REST风格的框架?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这个问题太宽用一个简单的使用这个框架来回答,但我真的AP preciate您的一个建议。

I know this question is too wide to be answered with a simple "use this framework", but I would really appreciate your advice on that one.

我期待做一个(相当复杂)项目比将运行的API。我接受任何编程语言(PHP,Python和Java的大部分),并发现了许多被更注重做一个RESTful Web服务器框架。

I'm looking to make a (quite complex) project than will run over an API. I'm open to any programming language (PHP, Python, Java mostly) and found many frameworks that are more oriented to make a RESTful web server.

唯一的主要约束我是,我将有一个可重复使用的,简单的和不可─code-意大利面条独立封装为了以后方便地提高自己的API,甚至切换到没有疼痛的其他框架。

The only major constraint I have is that I would have a reusable, simple and not-code-spaghetti independent package in order to improve my API later easily or even switch to an other framework with no pain.

对于Python和放大器; Java中,我想到了制作一个专门的包。每个动作会调用封装专用方法,包将返回的对象/字典和行动将其转换为正确的格式。

经过多方考证,我用两个框架,可能是对我的工作,但之间犹豫的我需要你的意见,因为我不会犯任何错误在这里。

After many research, I hesitate between two framework that could be good for my work but I need your advice because I wouldn't make any mistakes here.


  1. 播放!框架(JAVA)

    • 赞成

      • 路由器是基于REST的面向(您定义的方法(GET,POST等),请求和使用class.method)

      • 您不必每次做动作一个类

  1. Play! Framework (Java)
    • Pros :
      • Router are RESTFul oriented (you define the method (GET, POST, etc), the request and the class.method to use)
      • You don't have to make one class per action

  • 的模型是已经包括在内。如果我以后要更改的框架,也许我会用它卡住(但显然不是因为玩游戏!似乎使用JPA)

  • 也许是事实,如果我想的参数发送到将在方法签名中定义的动作,我不得不采取ClassName.properties,而不是像JSON的{类名:{属性:'值'}}


  • 赞成

    • 似乎是非常强大:由FriendFeed的使用(至少)

    • 验证通过主要的OpenID,OAuth的和Facebook已经实施

    • 很轻(可能是一个问题)


    • 不那么受欢迎:你通过进入code比文档更好地理解作品

    • 的url似乎是非常基本的(据我看到它,你必须定义在一个文件中的所有网址,并包括所有的类)

    • 每行动一类(可能是重度)

    • 为基础(如果测试用户身份验证等),装饰必须由

    有关在生产中使用它们,这将是与Apache和放容易做到; mod_proxy模块或nginx的。

    For using them in production, it would be easily possible with apache & mod_proxy or nginx.

    所以,我的问题很简单:你会选择什么(这两个或其他人之间,我不是封闭的建议),为什么

    So, my questions is quite simple : what would you choose (between those two or others, I'm not closed to suggestions) and why ?

    谢谢你真的太多的咨询!

    推荐答案

    我最喜欢的RESTful Web应用程序开发框架是的Restlet 。这是一个Java框架/库(可为任一想到),但它与 Jython的并的JRuby ,所以如果你preFER这些语言你仍然可以使用它。我大多与的Groovy 使用它。

    My favorite RESTful Web App development framework is Restlet. It's a Java framework/library (it can be thought of as either) but it works well with Jython and JRuby, so if you prefer those languages you could still use it. I mostly use it with Groovy.

    我preFER的Restlet,因为:

    I prefer Restlet because:


    • 它的API完全拥护和REST风格的范例对齐,所以它鼓励你REST的工作。例如,当一个路由器路由到 ServerResource ,它会创建<$ C $的新实例的请求C> ServerResource 为每个请求。这鼓励的实施是无状态的。并有丰富的类层次结构与所有实施一个RESTful Web应用程序所需的概念:客户端,服务器,协议,虚拟主机,请求,响应的MediaType,状态等

    • Its API fully embraces and aligns with RESTful paradigms, so it encourages you to work RESTfully. For example, when a Router routes a request to a ServerResource, it creates a new instance of the ServerResource for every request. This encourages the implementation to be stateless. And there's a rich class hierarchy with all the concepts required to implement a RESTful web app: Client, Server, Protocol, VirtualHost, Request, Response, MediaType, Status, etc.

    它的API包括类编写服务器和客户端,而且他们非常一致,几乎对称的。例如,有一个 ServerResource 类和 ClientResource 类。 ServerResource.get() ClientResource.get()都返回一个重新presentation 。唯一的区别是,你实现 ServerResource.get()键,重新生成presentation的响应,而你叫 ClientResource.get()并获得重新presentation的响应。

    Its API includes classes for writing both servers and clients, and they're very consistent and almost symmetrical. For example, there's a ServerResource class and a ClientResource class. ServerResource.get() and ClientResource.get() both return a Representation. The only difference is that you implement ServerResource.get() and generate a response representation, while you call ClientResource.get() and receive a response representation.

    该API与Jav​​a约定一致。例如,如果一个请求以 ClientResource.get取得()收到一个错误的响应,如401, ResourceException 将被抛出。如果你正在实施 ServerResource ,并希望返回一个错误,你只是抛出一个 ResourceException (这是一个的RuntimeException ,这是很好)。

    The API is consistent with Java conventions. For example, if a request made with ClientResource.get() receives an error response such as 401, a ResourceException will be thrown. And if you're implementing a ServerResource and want to return an error status, you just throw a ResourceException (which is a RuntimeException, which is nice).

    通过其扩展机制,它起着非常漂亮,与周围的最好的Java库浩如烟海。扩展名包括关于各种HTTP客户端和服务器库,数据库,模板库,安全库,数据库诸如XML,JSON OAuth的,OData的,等等,甚至OSGI

    Via its extension mechanism, it plays very nicely with a broad array of the best Java libraries around. Extensions are included for various HTTP client and server libraries, databases, templating libraries, security libs, data libs such as XML, JSON, OAuth, OData, etc., and even OSGI.

    部署非常灵活。您可以在现有的Java应用程序,将现有的Java Servlet应用程序,或任何标准的Java Web应用程序(Servlet的)服务器嵌入的Restlet供电的API。或者你可以构建比如Jetty嵌入式HTTP服务器的独立服务器的应用程序 - 这是我的preferred方法。因为它在JVM上运行,它运行在几乎所有的硬件​​或操作系统。

    Deployment is very flexible. You can embed a Restlet-powered API in an existing Java app, an existing Java Servlet app, or any standard Java Web App (Servlet) server. Or you can build a stand-alone server app with an embedded HTTP server such as Jetty — that's my preferred approach. And because it runs on the JVM, it runs on almost any hardware or OS.

    这是成熟,可靠,负责任地维护,稳步提高,并深受社会各界的支持和都商业。

    It's mature, reliable, responsibly maintained, steadily improving, and well supported both by the community and commercially.

    它是开源的,并且具有非常清晰,结构良好的code。开发商乐于接受任何贡献。我已经提交了几个补丁,并让他们致力于与没有戏剧快速主干。

    It's open source, and has very clear and well-structured code. The developers are happy to accept any contributions. I've submitted a few patches and had them committed to trunk quickly with no drama.

    其他选项我建议将是Python的microframework 和红宝石microframework的西纳特拉。他们都是简单,直接,重量轻,有效。因为他们与WSGI和机架堆叠的工作,有一个丰富的,可以很容易地与他们使用的中间件模块。

    Other options I'd suggest would be the Python microframework Bottle and the Ruby microframework Sinatra. They're both simple, straightforward, lightweight, and effective. And because they work with the WSGI and Rack stacks, there's a rich set of "middleware" modules which can easily be used with them.

    这篇关于如何选择完美的REST风格的框架?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆