加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

REST another WebService???

发布时间:2020-12-16 22:26:47 所属栏目:安全 来源:网络整理
导读:一、什么是REST REST stands for Representational State Transfer. (It is sometimes spelled "ReST".) It relies on a stateless,client-server,cacheable communications protocol -- and in virtually all cases,the HTTP protocol is used. REST is an

一、什么是REST

REST stands for Representational State Transfer. (It is sometimes spelled "ReST".) It relies on a stateless,client-server,cacheable communications protocol -- and in virtually all cases,the HTTP protocol is used.


REST is an architecture style for designing networked applications. The idea is that,rather than using complex mechanisms such as CORBA,RPC or SOAP to connect between machines,simple HTTP is used to make calls between machines.


In many ways,the World Wide Web itself,based on HTTP,can be viewed as a REST-based architecture.

RESTful applications use HTTP requests to post data (create and/or update),read data (e.g.,make queries),and delete data. Thus,REST uses HTTP for all four CRUD (Create/Read/Update/Delete) operations.


REST is a lightweight alternative to mechanisms like RPC (Remote Procedure Calls) and Web Services (SOAP,WSDL,et al.). Later,we will see how much more simple REST is.


Despite being simple,REST is fully-featured; there's basically nothing you can do in Web Services that can't be done with a RESTful architecture.

REST is not a "standard". There will never be a W3C recommendataion for REST,for example. And while there are REST programming frameworks,working with REST is so simple that you can often "roll your own" with standard library features in languages like Perl,Java,or C#.


三、How simple is REST?

Let's take a simple web service as an example: querying a phonebook application for the details of a given user. All we have is the user's ID.

Using Web Services and SOAP,the request would look something like this:

<?xml?version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
?<soap:body?pb="http://www.acme.com/phonebook">
??<pb:GetUserDetails>
???<pb:UserID>12345</pb:UserID>
??</pb:GetUserDetails>
?</soap:Body>
</soap:Envelope>

(The details are not important; this is just an example.) The entire shebang now has to be sent (using an HTTP POST request) to the server. The result is probably an XML file,but it will be embedded,as the "payload",inside a SOAP response envelope.

And with REST? The query will probably look like this:

http://www.acme.com/phonebook/UserDetails/12345

Note that this isn't the request body -- it's just a URL. This URL is sent to the server using a simpler GET request,and the HTTP reply is the raw result data -- not embedded inside anything,just the data you need in a way you can directly use.

  • It's easy to see why Web Services are often used with libraries that create the SOAP/HTTP request and send it over,and then parse the SOAP response.

  • With REST,a simple network connection is all you need. You can even test the API directly,using your browser.

  • Still,REST libraries (for simplifying things) do exist,and we will discuss some of these later.

Note how the URL's "method" part is not called "GetUserDetails",but simply "UserDetails". It is a common convention in REST design to use?nouns?rather than?verbs?to denote simple?resources.

The letter analogy
A nice analogy for REST vs. SOAP is mailing a letter: with SOAP,you're using an envelope; with REST,it's a postcard. Postcards are easier to handle (by the receiver),waste less paper (i.e.,consume less bandwidth),and have a short content. (Of course,REST requests aren't really limited in length,esp. if they use POST rather than GET.)

But don't carry the analogy too far: unlike letters-vs.-postcards,REST is every bit as secure as SOAP. In particular,REST can be carried over secure sockets (using the HTTPS protocol),and content can be encrypted using any mechanism you see fit. Without encryption,REST and SOAP are both insecure; with proper encryption in place,both are equally secure.

BY?DR. M. ELKSTEIN

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读