什么被归类为 RESTful Web 服务 [英] What gets classified as a RESTful Web Service

查看:48
本文介绍了什么被归类为 RESTful Web 服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我目前有一个调用 Web 服务来检索数据的应用程序,我在一个 url 上执行基本的 HTTP GET,就像 www.example.com/service.asmx?param1=1&param2=2这将返回一些我解析的 xml.

So I currently have an application that calls a web service to retrieve data, where I do a basic HTTP GET on a url like so www.example.com/service.asmx?param1=1&param2=2 This returns some xml which I parse.

我的问题是,这是否将其归类为 RESTful Web 服务?我想不,但我想知道是什么使它成为 REST 网络服务?

My question is, does this classify it as a RESTful Web Service? I am thinking no, but I'd like to know what makes it a REST web-service?

我知道有 REST 和 SOAP Web 服务,但是上面的情况如何归类为简单的 HTTP GET Web 服务?还是什么?

I know there are REST and SOAP web services, but what would the above case be classified as, simple HTTP GET Web service? or something?

谢谢,我正在尝试将术语与概念相匹配,如果这有点太初级,请原谅我.

Thanks, I am trying to match terminology to concepts, forgive me if this is a bit too elementary.

推荐答案

您的问题的直接答案是否定的.

The direct answer to your question is No.

分解您告诉我们的关于您的服务的内容,我将讨论关于您的解决方案什么是非 RESTful.

Breaking down what you have told us about your service I will discuss what is an is not RESTful about your solution.

HTTP GET 在这样的 url 上www.example.com/service.asmx?param1=1&param2=2

HTTP GET on a url like so www.example.com/service.asmx?param1=1&param2=2

您正在使用 HTTP GET,因此正在使用一组有限的动词之一通过 URI 访问某种资源.这是 RESTful 并且符合统一接口约束,只要服务器不违反任何关于允许 GET 做什么的 HTTP 规则.

You are using an HTTP GET and are therefore using one of a limited set of verbs to access some kind of resource via a URI. This is RESTful and conforms to the uniform interface constraint as long as the server does not violate any of HTTP rules about what a GET is allowed to do.

查看 URL 本身,您访问的资源并不明显,因此它确实暗示您的 URL 空间的结构可能不便于进行 RESTful 设计.但是,REST 不会对您的 URL 应该是什么样子施加任何限制(尽管很多人都这么认为),因此您的 URL 没有任何不符合 REST 的地方.

Looking at the URL itself, it is not apparent what resource you are accessing and therefore it does hint that your URL space may not be structured in a way that is convenient for doing RESTful design. However, REST does not put any constraints on what your URL should look like (despite what soooooooo many people think), so there is nothing unRESTful with your URL.

这将返回一些我解析的 xml.

This returns some xml which I parse.

这就是您的问题开始的地方.我在这条语句中隐含地读到的是,客户端知道如何解析 XML 中的数据.这违反了 REST 的自描述约束.http 消息应包含客户端了解如何处理来自请求的响应所需的所有信息.媒体类型应该告诉客户端 XML 文档中有哪些信息.如果您的服务返回 application/xml,那么客户端唯一知道的是该文档包含属性和元素.如果客户端使用带外知识来解析该 XML,那么您正在引入客户端和服务器之间的耦合.REST 的主要目标之一是消除这种耦合.

Here is where your problems start. What I am reading implicitly in this statement is that the client knows how to parse the data out of your XML. This is a violation of the Self-descriptive constraint of REST. The http message should contain all of the information that is needed for the client to know how to process the response from a request. The media-type should tell the client what information is in the XML document. If your service returns application/xml then the only thing the client knows is that the document contains attributes and elements. If the client uses out-of-band knowledge to parse that XML then you are introducing coupling between the client and the server. One of the major objectives of REST is to eliminate that coupling.

服务必须遵守许多其他约束才能被视为 RESTful,但您没有提供有关您的服务的足够详细信息,无法以一种或另一种方式说明它是否合规.

There are a number of other constraints that a service must respect in order to be considered RESTful, but you do not provide sufficient detail about your service to say one way or another if it is compliant.

这篇关于什么被归类为 RESTful Web 服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆