简体   繁体   English

如何使REST请求像RPC一样更加用户友好?

[英]How to make REST requests more user friendly like RPC?

I've been highly considering creating a REST service rather than RPC but it seems to me that a client/user will have to write a significant amount of code to achieve the same thing compared with an RPC service. 我一直在考虑创建REST服务而不是RPC,但在我看来,与RPC服务相比,客户端/用户必须编写大量代码才能实现相同的目的。 Moreover, implementing a REST service would require a user some basic knowledge about REST. 此外,实施REST服务将要求用户具有一些有关REST的基本知识。 To illustrate in PHP: 在PHP中进行说明:

REST 休息

  • To send GET, POST, PUT, DELETE request the user must send his request using CURL 要发送GET,POST,PUT,DELETE请求,用户必须使用CURL发送其请求
  • Of course this requires his server to have CURL enabled, not good for some shared host 当然,这需要他的服务器启用CURL,不利于某些共享主机
  • Aside from the data parameters the users needs to send, CURL requires additional lines of code to send the request. 除了用户需要发送的数据参数外,CURL还需要其他代码行来发送请求。

RPC RPC

  • To send a similar request with an RPC service, the user simply calls a URL together with data parameters. 要使用RPC服务发送类似的请求,用户只需调用URL和数据参数即可。 ie: example.com?foo=bar&baz=quz 即:example.com?foo = bar&baz = quz

Is there a way to make REST as "easy" as RPC. 有没有办法使REST和RPC一样“容易”。 I'm thinking of encapsulating REST request with RPC methods but that breaks the whole idea isn't it? 我正在考虑使用RPC方法封装REST请求,但这打破了整个想法,不是吗?

REST does not force you to use GET, POST, PUT and DELETE. REST不会强制您使用GET,POST,PUT和DELETE。 it just means that a single URL represents a single content. 它仅表示单个URL表示单个内容。 you can also implement a RESTful behaviour like this: 您还可以实现这样的RESTful行为:

GET /index.php
GET /item.php?id=x
POST /create.php
POST /update.php
POST /delete.php

even create, update and delete could be done with get requests... 甚至创建,更新和删除也可以通过获取请求来完成...

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

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