REST 和 RPC 之间的 Web 服务差异 [英] Web service differences between REST and RPC
问题描述
我有一个接受 JSON 参数并具有特定方法 URL 的 Web 服务,例如:
I have a web service that accepts JSON parameters and have specific URLs for methods, e.g.:
http://IP:PORT/API/getAllData?p={JSON}
这绝对不是 REST,因为它不是无状态的.它会考虑 cookie 并拥有自己的会话.
This is definitely not REST as it is not stateless. It takes cookies into account and has its own session.
是RPC吗?RPC 和 REST 有什么区别?
Is it RPC? What is the difference between RPC and REST?
推荐答案
仅通过查看您发布的内容,您无法明确区分 REST 或 RPC.
You can't make a clear separation between REST or RPC just by looking at what you posted.
REST 的一个限制是它必须是无状态的.如果你有一个会话,那么你就有状态,所以你不能调用你的服务 RESTful.
One constraint of REST is that it has to be stateless. If you have a session then you have state so you can't call your service RESTful.
您在 URL 中有一个操作(即 getAllData
)这一事实表明了 RPC.在 REST 中,您交换表示,您执行的操作由 HTTP 动词决定.此外,在 REST 中,内容协商不使用 ?p={JSON}
参数.
The fact that you have an action in your URL (i.e. getAllData
) is an indication towards RPC. In REST you exchange representations and the operation you perform is dictated by the HTTP verbs. Also, in REST, Content negotiation isn't performed with a ?p={JSON}
parameter.
不知道你的服务是否是 RPC,但它不是 RESTful.您可以在线了解差异,这里有一篇文章可以帮助您入门:揭穿 RPC & 的神话休息.您更了解服务内部的内容,因此将其功能与 RPC 进行比较并得出您自己的结论.
Don't know if your service is RPC, but it is not RESTful. You can learn about the difference online, here's an article to get you started: Debunking the Myths of RPC & REST. You know better what's inside your service so compare it's functions to what RPC is and draw your own conclusions.
这篇关于REST 和 RPC 之间的 Web 服务差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!