SlideShare a Scribd company logo
1 of 18
RESTful任我行 RESTful介绍及最佳实践 Medcl,2010.6.4
前情提要 REST是什么? Why RESTful ? RESTful.NET !
REST、RESTful??? Roy Thomas Fielding博士2000年提出 REST是英文Representational State Transfer的缩写 REST是WEB服务的一种架构风格 REST一种新型的分布式软件设计架构 使用HTTP、URI等广泛流行的标准和协议
 REST 架构的主要原则 网络上的所有事物都可被抽象为资源(Resource) 每个资源都有一个唯一的资源标识符(Resource Identifier) 同一资源具有多种表现形式(xml、json等) 对资源的各种操作不会改变资源标识符 所有的操作都是无状态的(Stateless) Ps:符合REST原则的架构方式即可称为RESTful
资源、资源、资源 处处皆资源(Resource): 2010公司的销售数据 小明09年一月份看过的书 正在上映的电影 公司销售的产品清单 … … REST与资源 REST面向的对象是资源 RE——表现,即media type的设计。  ST——通过跟踪超链接实现状态迁移。
资源与URIDesign RESTful风格的一大特色就是使用URI来标示资源 URI 和 URL http://example.com/users/http://example.com/users/{user} (one for each user) http://example.com/findUserForm http://example.com/locations/ http://example.com/locations/{location} (one for each location) http://example.com/findLocationForm
资源操作 http://example.com/users/ GET  :获取一个资源 POST :创建一个新的资源 PUT :修改一个资源的状态 DELETE :删除一个资源 
资源展现 Xml Json Xhtml RSS/Atom Other Media types
无状态性 无状态性使得客户端和服务器端不必保存对方的详细信息,服务器只需要处理当前 Request,而不必了解前面 Request 的历史 无状态性减少了服务器从局部错误中恢复的任务量,可以非常方便地实现 Fail Over 技术,从而很容易地将服务器组件部署在集群内 无状态性使得服务器端不必在多个 Request 中保存状态,从而可以更容易地释放资源 无状态性无需服务组件保存 Request 状态,因此可让服务器充分利用 Pool 技术来提高稳定性和性能
RESTful优缺点 SOAP、WSDL、WS* REST  RPC 样式的架构中,关注点在于方法,而在 REST 样式的架构中,关注点在于资源 SO WHY REST? 轻量级、HTTP 无状态请求可以由任何可用服务器回答,分布式、缓存、云计算 资源唯一URI、标准接口 基于成熟HTTP的安全模型 Simplicity、human-friendly … …
REST不是什么? REST不是技术  REST不是CRUD
RESTful.NET REST在.NET平台下的最佳实践 WCF RESTful Programming Model Hosting WCF RESTful Services Securing REST Endpoints
前提准备 WCF REST Service Start Kit  visual studio 2008 sp1   .net framework 3.5 sp1 Fiddler(客户端调试)
URI http://localhost:8080/rest/User http://localhost:8080/rest/User/{userName} http://localhost:8080/rest/User/xml 	/// <summary> /// 用户信息 	/// </summary> 	[DataContract(Name = "User")] 	public class UserInfo { 		[DataMember] 		public string UserName; 		[DataMember] 		public string Birthday; }
添加 POST http://localhost:8080/rest/User User-Agent: Fiddler Host: localhost:8080 Content-Length: 22 Content-Type: application/json {"userName":"Aobama"}
修改 PUT http://localhost:8080/rest/User Content-Length: 53 Content-Type: application/json Host: localhost:8080 {"user":{"Birthday":"197711","UserName":"medcl"}}
查询 http://localhost:8080/rest/User http://localhost:8080/rest/User/admin http://localhost:8080/rest/User/xml http://localhost:8080/rest/Icon/
Restful

More Related Content

Similar to Restful

语义互操作与关联数据
语义互操作与关联数据语义互操作与关联数据
语义互操作与关联数据Shanghai Library
 
关联数据Abc与近年进展
关联数据Abc与近年进展关联数据Abc与近年进展
关联数据Abc与近年进展Shanghai Library
 
中正大學/FHIR 快速掃描 R4 版本
中正大學/FHIR 快速掃描 R4 版本中正大學/FHIR 快速掃描 R4 版本
中正大學/FHIR 快速掃描 R4 版本Lorex L. Yang
 
Rest与面向资源的web开发
Rest与面向资源的web开发Rest与面向资源的web开发
Rest与面向资源的web开发topgeek
 
关联数据Abc与近年进展
关联数据Abc与近年进展关联数据Abc与近年进展
关联数据Abc与近年进展Shanghai Library
 
Json ld 簡介
Json ld 簡介Json ld 簡介
Json ld 簡介bobo52310
 
腾讯大讲堂25 企业级搜索托管平台介绍
腾讯大讲堂25 企业级搜索托管平台介绍腾讯大讲堂25 企业级搜索托管平台介绍
腾讯大讲堂25 企业级搜索托管平台介绍George Ang
 
Fast Esp搜索系统
Fast Esp搜索系统Fast Esp搜索系统
Fast Esp搜索系统xiaochawan
 
Restful & odata using asp.net web api
Restful & odata using asp.net web apiRestful & odata using asp.net web api
Restful & odata using asp.net web api昱劭 劉
 
REST to RESTful Web Service
REST to RESTful Web ServiceREST to RESTful Web Service
REST to RESTful Web Service家弘 周
 

Similar to Restful (15)

语义互操作与关联数据
语义互操作与关联数据语义互操作与关联数据
语义互操作与关联数据
 
关联数据Abc与近年进展
关联数据Abc与近年进展关联数据Abc与近年进展
关联数据Abc与近年进展
 
中正大學/FHIR 快速掃描 R4 版本
中正大學/FHIR 快速掃描 R4 版本中正大學/FHIR 快速掃描 R4 版本
中正大學/FHIR 快速掃描 R4 版本
 
Kevenjiaoda
KevenjiaodaKevenjiaoda
Kevenjiaoda
 
资源整合与Web2.0
资源整合与Web2.0资源整合与Web2.0
资源整合与Web2.0
 
资源整合与Web2.0
资源整合与Web2.0资源整合与Web2.0
资源整合与Web2.0
 
Rest与面向资源的web开发
Rest与面向资源的web开发Rest与面向资源的web开发
Rest与面向资源的web开发
 
关联数据Abc与近年进展
关联数据Abc与近年进展关联数据Abc与近年进展
关联数据Abc与近年进展
 
Json ld 簡介
Json ld 簡介Json ld 簡介
Json ld 簡介
 
腾讯大讲堂25 企业级搜索托管平台介绍
腾讯大讲堂25 企业级搜索托管平台介绍腾讯大讲堂25 企业级搜索托管平台介绍
腾讯大讲堂25 企业级搜索托管平台介绍
 
Fast Esp搜索系统
Fast Esp搜索系统Fast Esp搜索系统
Fast Esp搜索系统
 
Restful & odata using asp.net web api
Restful & odata using asp.net web apiRestful & odata using asp.net web api
Restful & odata using asp.net web api
 
REST to RESTful Web Service
REST to RESTful Web ServiceREST to RESTful Web Service
REST to RESTful Web Service
 
Intro to REST
Intro to RESTIntro to REST
Intro to REST
 
Intro to rest
Intro to restIntro to rest
Intro to rest
 

More from medcl

Using SaltStack To AutoDeploy ElasticSearch
Using SaltStack To AutoDeploy ElasticSearchUsing SaltStack To AutoDeploy ElasticSearch
Using SaltStack To AutoDeploy ElasticSearchmedcl
 
Elastic Search Training#1 (brief tutorial)-ESCC#1
Elastic Search Training#1 (brief tutorial)-ESCC#1Elastic Search Training#1 (brief tutorial)-ESCC#1
Elastic Search Training#1 (brief tutorial)-ESCC#1medcl
 
ElasticSearch Training#2 (advanced concepts)-ESCC#1
ElasticSearch Training#2 (advanced concepts)-ESCC#1ElasticSearch Training#2 (advanced concepts)-ESCC#1
ElasticSearch Training#2 (advanced concepts)-ESCC#1medcl
 
Git 使用介绍
Git 使用介绍Git 使用介绍
Git 使用介绍medcl
 
数据挖掘理论与实践
数据挖掘理论与实践数据挖掘理论与实践
数据挖掘理论与实践medcl
 
Elastic search intro-@lamper
Elastic search intro-@lamperElastic search intro-@lamper
Elastic search intro-@lampermedcl
 
quick intro to elastic search
quick intro to elastic search quick intro to elastic search
quick intro to elastic search medcl
 

More from medcl (7)

Using SaltStack To AutoDeploy ElasticSearch
Using SaltStack To AutoDeploy ElasticSearchUsing SaltStack To AutoDeploy ElasticSearch
Using SaltStack To AutoDeploy ElasticSearch
 
Elastic Search Training#1 (brief tutorial)-ESCC#1
Elastic Search Training#1 (brief tutorial)-ESCC#1Elastic Search Training#1 (brief tutorial)-ESCC#1
Elastic Search Training#1 (brief tutorial)-ESCC#1
 
ElasticSearch Training#2 (advanced concepts)-ESCC#1
ElasticSearch Training#2 (advanced concepts)-ESCC#1ElasticSearch Training#2 (advanced concepts)-ESCC#1
ElasticSearch Training#2 (advanced concepts)-ESCC#1
 
Git 使用介绍
Git 使用介绍Git 使用介绍
Git 使用介绍
 
数据挖掘理论与实践
数据挖掘理论与实践数据挖掘理论与实践
数据挖掘理论与实践
 
Elastic search intro-@lamper
Elastic search intro-@lamperElastic search intro-@lamper
Elastic search intro-@lamper
 
quick intro to elastic search
quick intro to elastic search quick intro to elastic search
quick intro to elastic search
 

Restful