http://blog.youkuaiyun.com/kelitewang/article/details/7170267
REST(Representation State Transfer)资源表示状态转移
1、必须无状态,请求可以在不同server之间分派,适合分布式服务
2、资源通过单一URI表示,比如http://oo.xx.com/account/contact,URI中只表示资源,动词。 动作信息通过Http协议的GET, POST, PUT, DELETE表示
满足以上条件的服务,可以被称作RESTFul风格的服务
误区:
http://oo.xx.com/account/contact_by_id
http://oo.xx.com/account/list_contacts
http://oo.xx.com/account/search_contact
对于上述URI,不符合条件2。完整RESTFul风格的服务API应该是:
http://oo.xx.com/account/contact
http://oo.xx.com/account/contacts
http://oo.xx.com/account/contact/search
资源可以是一种服务,这样避免了在API中包含动作信息
RPC风格:
调用http://oo.xx.com/service.do,post body为xml,包含方法名,参数。
<xml><method>/account/get_contact_by_id</method><params></params></xml>
REST-RPC风格:
http://oo.xx.com/service.do?method=/account/get_account_by_id¶ms=xxxooo
将表示资源的method放在url中,因为不是uri中,所以不是restful的,但是整串url表示了一个资源,可以认为有rest风格。
SOAP(Simple Object Access Protocol)简单对象访问协议
请求通过xml格式,告知服务器端,需要访问的资源、参数。如
<?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:Header> <m:Trans xmlns:m="http://www.w3school.com.cn/transaction/" soap:mustUnderstand="1" soap:actor="http://www.w3school.com.cn/appml/">234</m:Trans> </soap:Header> <soap:Body xmlns:m="http://www.example.org/stock"> <m:GetStockPrice> <m:StockName>IBM</m:StockName> </m:GetStockPrice> </soap:Body> </soap:Envelope>
同样通过xml格式包装数据进行response响应。
比RPC更多的一点是,通过xml中的格式约定(WSDL web services description language),客户端和服务端就接口协议可以达成一致。