对 RESTful Web 服务有疑问吗?

发布于 2024-11-02 02:29:52 字数 510 浏览 4 评论 0原文

我是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

半夏半凉 2024-11-09 02:29:52

通常没有机器可读的服务描述。您通常可以通过阅读服务文档来了解要发送的内容。

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 like http://example.com/add?3,5.

You can find a list of REST services at http://www.programmableweb.com/apis/directory/1?protocol=REST.

っ〆星空下的拥抱 2024-11-09 02:29:52

回答你的第一个问题:

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.

安穩 2024-11-09 02:29:52
  1. 没有 WSDL/WADL 文件。您可以获得 HTTP 协议(​​例如 GET、POST、UPDATE、DELETE),其他一切都由您决定。确保相应地记录您的预期输入和输出。
  2. 不,RESTful Web 服务不限于 CRUD。对于您的添加服务,我会将其实现为“加法器”资源,该资源会将要添加的 2 个数字作为输入。您可以将这些输入作为 url 路径 (http://yourdomain.com/adder/1/2) 或查询字符串参数 (http://yourdomain.com/adder?var1=2&var2=2) 的一部分) 或作为来自 HTTP POST 的输入。由你决定。
  1. No WSDL/WADL files. You get the HTTP protocol (e.g. GET, POST, UPDATE, DELETE) and everything else is up to you. Make sure to document your expected inputs and outputs accordingly.
  2. No, RESTful web services are not restricted to CRUD. For your adding service, I would implement it as an "adder" resource which would take as input the 2 numbers to add. You could take these inputs as part of the url path (http://yourdomain.com/adder/1/2) or in the query string params (http://yourdomain.com/adder?var1=2&var2=2) or as inputs from an HTTP POST. Up to you.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文