REST与RPC在PHP中 [英] REST vs. RPC in PHP

查看:141
本文介绍了REST与RPC在PHP中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立自己的Ajax网站,我正在考虑 REST 和RPC。



如果我的服务器支持Servlets,我只需安装坚持并结束问题,但是我的服务器不支持Servlet。



RPC更简单的代码(IMO),可以很容易地用PHP编写。我只需要一个数据库查询执行器。我正在使用 Dojo Toolkit 和JSON。



为什么我应该通过REST选择REST over RPC或RPC?

解决方案

Uhm ...把​​它简单,都是非常抽象的模型,所以抽象,它们自然地发生在任何地方...



REST是将资源定位到全局标识符(URI in在 CRUD 中访问的HTTP的情况)(使用 POST GET ,在HTTP的情况下为PUT和DELETE ...好吧,至少这是想法)...



RPC是您在不同机器上调用过程的想法,传递一些参数ameters,并返回值...



在维基百科上有一个很好的简短比较



Persevere创建一个服务,允许两者(以非常优雅的方式,诚然)...它是 RESTful (尽管它不仅使用HTTP功能来实现这一点)暴露了一个RPC界面...



最后,你应该看看你的应用程序需要做什么...像大多数人一样,您可能会使用RPC API(基于 XML JSON 或其他),包括部分REST的子系统的传输层...这是因为有RESTfulnes,意思是flexibil ity ...如果客户端可以或多或少地自由地遍历服务器上的数据(通过一组简单的CRUD方法),它不依赖于通过API公开的有限(特定于问题的)一组方法,而您可以转移逻辑客户端...


I'm building my own Ajax website, and I'm contemplating between REST and RPC.

If my server supported Servlets I'd just install persevere and end the problem, but my server doesn't support Servlets.

RPC is simpler to code (IMO) and can be written in PHP easily. All I need is a database query executer. I'm using the Dojo Toolkit and JSON.

Why should I choose REST over RPC or RPC over REST?

解决方案

Uhm ... to put it simple, both are very abstract models ... so abstract, they naturally occur everywhere...

REST is the idea of having resources addressed with a global identifier (the URI in the case of HTTP) that are accessed in a CRUD way (using POST, GET, PUT and DELETE in the case of HTTP ... well, at least that's the idea)...

RPC is the idea where you call a procedure on a different machine, passing in some parameters, and taking a return value...

There is a nice short comparison on Wikipedia

Persevere creates a service, that allows both (in a very elegant way, admittedly) ... it is RESTful (although it does not only use HTTP-features to achieve this) and exposes an RPC interface...

In the end, you should look at what your application needs to do ... as most people, you'll probably wind up with an RPC API (be it based on XML or JSON or whatever), that includes a transport layer for a partially RESTful subsystem ... this is, because having RESTfulnes, means flexibility ... if the client can more or less freely traverse the data on the server (through a set of simple CRUD methods), it does not depend on a limited (problem-specific) set of methods exposed through the API, and you can shift logic clientwards...

这篇关于REST与RPC在PHP中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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