Restful Web Service 特点
-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 请求间是存在关系的。
比如api:
http://..../nextpage
第一次发过去返回1,
第二次发过去返回2,
服务器那边肯定有个变量,每次收到这个请求,都需要 ++
那么,如果有多台服务器呢?由LB相连。这次我去了这台服务器,下次我去了那台服务器。万一那台服务器没++呢?返回的页面就错了。所以必须考虑到多台服务器的synchronized 问题。这是state web service 必须考虑的。写起来会很麻烦。
服务器之间需要通信。那么信息必须可被synchronize.
同时,还得考虑available, reliable等等多方面问题。会很麻烦。
但是stateless web service 就不需要啊。我完全没有状态。
但是,我也不会设计 http://..../nextpage 这样的api
前端会将页数发过来,
http://..../page_number/3
http://..../page_number/4
...
以此类推,就可以避免很多很复杂很浪费服务器资源的同步问题了。
-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 机制。 在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.
前后台统一了通信语言格式。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.
感觉只要说出前三点并且配备足够的解释就差不多了
- stateless
- cache
- same form of communication language: JSON/XML