对 RESTful Web 服务有疑问吗?
我是 RESTful 服务领域的新手。我一直在阅读有关 REST 的文章。我有很多疑问。请帮我解答这些疑惑。提前致谢。
1) 对于所有 RESTful Web 服务,是否会有 WSDL/WADL 来描述服务?是否必须有服务描述?如果没有描述,我如何知道我必须沿着 HTTPRequest 发送的数据及其结构?
我读到,请求内容可以是任何类型(XML、JSON、YAML 等)。并且对于可以随请求发送的内容类型没有限制。如果没有描述,我如何知道我应该发送的数据类型?
2)通过阅读文章,我得到的印象是RESTful服务主要用于CRUD操作类型的服务。不同的 HTTP 动词用于不同的操作。但如果你采用Web服务,它就可以做各种操作。例如,将 2 个数字相加并不完全是 CRUD 操作。如果我对可以为我执行此操作的资源使用 GET/POST,那么这是否会违反 REST 原则?
3) 如果您可以向我指出任何可用于测试的公共 RESTful Web 服务,我可以尝试使用该服务并了解该服务的复杂程度。
预先感谢,
保罗
I am new to the arena of RESTful services. I have been going through the articles about REST. And I have a lots of doubts. Please help me to clear these doubts. Thanks in advance.
1) For all RESTful web services, will there be a WSDL/WADL for describing the service? Is it mandatory to have service description? If there is no description, how can I know the data and its structure that I have to send along the HTTPRequest?
I read like, the request content could be any type (XML, JSON, YAML etc.). And there is no restriction for the content-type that could be send with request. Without a description how can I know the type of data that I am supposed to send?
2) By going through the articles, I have got the impression that RESTful services is used mainly for CRUD operation kind of services. Different HTTP verbs for different operations. But if you take web services, it can do all kinds of operations. For example, adding 2 numbers is not exactly a CRUD operation. If I use GET/POST to the resource which could do this operations for me, then will it be a violation of REST principles?
3) If you can point me to any public RESTful webservices that could be used for testing, I could try using the service and get an idea how complex the services could be.
Thanks in advance,
Paul
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
通常没有机器可读的服务描述。您通常可以通过阅读服务文档来了解要发送的内容。
REST 不限于 CRUD,
PUT/GET/POST/DELETE
方法不一定与create/retrieve/update/delete相同>。基于 REST 的服务可以执行基于 SOAP 的 Web 服务可以执行的任何操作。将 GET 请求发送到像http://example.com/add?3,5
这样的 URI 是完全 RESTful 的。您可以在 http://www.programmableweb.com/ 找到 REST 服务列表apis/directory/1?protocol=REST。
There is normally no machine-readable service description. You would typically know what to send by reading the documentation for the service.
REST isn't limited to CRUD and the
PUT/GET/POST/DELETE
methods are not necessarily the same as create/retrieve/update/delete. REST-based services can do anything that SOAP-based web services can do. It is completely RESTful to send a GET request to a URI likehttp://example.com/add?3,5
.You can find a list of REST services at http://www.programmableweb.com/apis/directory/1?protocol=REST.
回答你的第一个问题:
WSDL/WADL 对于 Restful Web 服务来说不是强制性的。此外,WSDL 1.1 HTTP 绑定不足以描述静态 Web 服务。
然而,可以使用 WSDL 2.0 来描述它。当客户和提供商对合同有相互理解时,应该使用 Restful Web 服务。
看一下: http://www.ibm.com/developerworks/webservices /library/ws-restwsdl/
第二:是的,您可以通过增删改查操作完成几乎所有事情。就像之前的答案 http://example.com/add?3,5 中所述。是一个有效的crud。
Answer to your first question :
WSDL/WADL is not mandatory for restful webservices. Also, WSDL 1.1 HTTP binding was inadequate to describe restful webservice.
However, WSDL 2.0 can be used to describe it. Restful webservice should be used when the client and provider have mutual understanding of the contract.
Have a look at : http://www.ibm.com/developerworks/webservices/library/ws-restwsdl/
Second : Yeah, you can accomplish almost everything from crud operations. Like stated in previous answer http://example.com/add?3,5. is a valid crud.