Restful Web Service 特點(diǎn)
-1. The RESTful Web services are completely stateless. This can be tested by restarting the server and checking if the interactions are able to survive.
好處是什么?
stateless service is easier to host and maintain. It is more scalable.
Plus, it can provide better response time to request, as it is much easier to load balance them
什么是 state web service?
是,兩次Http 請求間是存在關(guān)系的。
比如api:
http://..../nextpage
第一次發(fā)過去返回1,
第二次發(fā)過去返回2,
服務(wù)器那邊肯定有個變量,每次收到這個請求,都需要 ++
那么,如果有多臺服務(wù)器呢?由LB相連。這次我去了這臺服務(wù)器,下次我去了那臺服務(wù)器。萬一那臺服務(wù)器沒++呢?返回的頁面就錯了。所以必須考慮到多臺服務(wù)器的synchronized 問題。這是state web service 必須考慮的。寫起來會很麻煩。
服務(wù)器之間需要通信。那么信息必須可被synchronize.
同時,還得考慮available, reliable等等多方面問題。會很麻煩。
但是stateless web service 就不需要啊。我完全沒有狀態(tài)。
但是,我也不會設(shè)計(jì) http://..../nextpage 這樣的api
前端會將頁數(shù)發(fā)過來,
http://..../page_number/3
http://..../page_number/4
...
以此類推,就可以避免很多很復(fù)雜很浪費(fèi)服務(wù)器資源的同步問題了。
-2. Restful services provide a good caching infrastructure over HTTP GET method (for most servers). This can improve the performance, if the data the Web service returns is not altered frequently and not dynamic in nature.
cache 機(jī)制。 在http header 里面定義了這個cache的有效期。
-3. The service producer and service consumer need to have a common understanding of the context as well as the content being passed along as there is no standard set of rules to describe the REST Web services interface.
前后臺統(tǒng)一了通信語言格式。JSON/XML
互相可以理解對方的意思
-4. REST services are easy to integrate with the existing websites and are exposed with XML so the HTML pages can consume the same with ease. There is hardly any need to refactor the existing website architecture. This makes developers more productive and comfortable as they will not have to rewrite everything from scratch and just need to add on the existing functionality.
-5. REST-based implementation is simple compared to SOAP.
感覺只要說出前三點(diǎn)并且配備足夠的解釋就差不多了
- stateless
- cache
- same form of communication language: JSON/XML