PHP 中最简单的 RPC 客户端方法
我被要求帮助朋友的公司开发一个网络应用程序。我的时间非常有限,我勉强接受了这个请求,但有一个条件。由于大部分逻辑都在后端进行,我建议我仅完成完整的后端,从而允许前端开发人员简单地与我的后端进行交互。
我计划用 Java EE 或 Python(使用 Pylons)做后端。目前这并不重要。我计划让我的后端完全准备好并进行单元测试,以便在我的工作完成后几乎不需要我的输入。
我知道他们有一个 PHP 程序员,但据我所知他是一个真正的菜鸟。我希望他基本上以最简单的方式与我的后端服务进行交互,而他无法“填充”它。它基本上是一个仅限 CRUD 的应用程序。
我可以将后端实现为可通过 Web 服务(例如 XML-RPC 或 SOAP)进行访问。甚至 RESTful API 也是可能的。
然而,我的主要目标是让 PHP 程序员可以轻松地与“菜鸟”交互,而不会感到困惑。最好我什至不想和他说话,因为我的日程安排非常繁忙,而且我不愿意做“支持电话”。我应该选择哪种方法?我欢迎任何建议和意见!
I've been asked to help a friend's company to bring up a web application. I have very limited time and I reluctantly accepted the request, at one condition. As most of the logic goes on in the back-end, I suggested that I would finish the complete back-end only, allowing a front-end developer to simply interface with my backend.
I plan to do the back-end in Java EE or Python (with Pylons). It does not really matter at this point. I plan to have my back-end completely ready and unit-tested, so that my input will hardly be needed after my work is done.
I know they have a PHP programmer, but as far as I could tell he is a real rookie. I want him to basically interface with my backend's services in the easiest possible way, with no way of him "stuffing" it up. It's basically a CRUD-only application.
I could implement the backend as accessible through a webservice such as XML-RPC or SOAP. Even a RESTful API could be possible.
However, my main objective is to make something that complete "noob" PHP programmer can easily interface with without getting confused. Preferably I do not even want to talk to him because I generally have an extremely busy schedule, and doing "support calls" is not something I am willing to do. Which approach should I choose? I would welcome any suggestions and inputs!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我个人会选择 REST API,可能带有 JSON 响应。对于简单的服务来说,SOAP 和 XML 可能有点繁琐,即使是最新手的 Web 开发人员也了解访问基本 URL 的概念,即使他们不理解 REST 的整体概念。在 PHP 中使用 URL 的方法有很多种,所以我确信他们能够想出一些东西,即使这是一个黑客工作而不是一个好的客户端包。
我也可能选择 JSON 编码和解码,因为它通常相当简单,而 XML 解析可能有点令人畏惧。
我还会至少编写一些有关该服务的基本文档,无论您选择什么格式。否则您将无法逃避支持电话。您的目标消费者必须拥有可用的远程操作的参考,或者发现这些操作的方法。准备好后,您可能需要 10 分钟来编写一些示例代码,而这 10 分钟可以为您节省大量电子邮件。
I would personally choose a REST API, probably with a JSON response. SOAP and XML can be a bit heavy-handed for simple services, and even the most novice web developer understands the concept of accessing a basic URL, even if they don't grok the overall concept of REST. There are myriads of ways to work with URLs in PHP, so I'm sure they'd be able to come up with something, even if it was a hack job instead of a nice client package.
I would also likely choose JSON encoding and decoding, as it's generally fairly straightforward, while XML parsing can be a bit more daunting.
I would also write up at least some basic documentation on the service, no matter what formats you choose. Otherwise there's no way you will escape support calls. Your target consumer must have a reference of the remote actions available to him, or a method to discover those actions. It would probably take you 10 minutes to whip up some example code when it's ready, and those 10 minutes could save you a lot of emailing.
绝对采用类似休息的实现,并返回查询字符串格式的输出。
请记住,php 会将类似数组的变量转换为 php 端的数组。
为您的参数输入查询字符串
:
p1=v1&p2=v2....
输出:
output1=var1&output[0]=var2;output[2]=var3
在 php 中访问它就像
Definitly go with a rest-like implementation, and return query string formatted output.
Just remember that php will turn array like variables into an array on the php side.
Take a query string for your parameters
Input:
p1=v1&p2=v2....
Output:
output1=var1&output[0]=var2;output[2]=var3
Accessing this in php is then a simple as
去过那里,做过那件事。
后端采用 Django,前端采用 PHP,由“我们做页面”承包商负责。我使用 JSON 创建了一个类似 REST 的 API,为他们提供了几个 5 行 PHP 函数来访问我的服务作为键值存储。
经过几次错误的开始(他们尝试了一种人为的重定向方案,而不是使用我发送给他们的功能),他们得到了它,之后一切都很顺利。
Been there, done that.
Backend in Django, frontend in PHP by a 'we do pages' contractor. i whipped up a REST-like API using JSON, provided them with a couple of 5-line PHP functions to access my service as a key-value store.
After a couple of false starts (where they tried a contrived and redirections scheme instead of using the functions i sent them), they got it and everything went smoothly after that.