Understanding REST and designing for itRESTful Design
Robert MacLeanwww.sadev.co.za@rmacleanBB&D ATCIntroductionHTTP BasicsURI’sMethodsStatus CodesContent TypeAuthenticationURI PlanningPatternsStyleAccidental ServicesExamplesActionsGuidelinesAnti-PatternsSecurityWrap UpAbout meAgendaWelcome
RESTAcronym? Representational State Transfer Source?Came about in 2000 doctoral dissertation of Roy Fielding
What is it?ROA – Resource Orientated ArchitectureWOA – Web Orientated ArchitectureThanks Gartner for another TLA It is a styleNOT APIInterfaceOfficial StandardA drop in replacement for SOAP
Benefits of RESTHighly scalableDesigned for HTTPEasy to consume & produceNo complex request/response model.No complex XML contractsEasy to understand for you and machinesURI + Method = Intent
HTTP BasicsREST builds on HTTP so you need to know HTTPHTTP is not HTMLHTTP is statelessHTTPURIHeaderhttp://www.sadev.co.zaMethodGETStatus Code200Content Typetext/plainBodytext
URI BasicsHostnameSchemeQueryhttp://www.sadev.co.za/users/1/contacthttp://www.sadev.co.za?user=1&action=contacthttp://rob:pass@bbd.co.za:8044https://bbd.co.za/index.html#aboutQueryHostnameSchemeUserinfoHostnamePortSchemeSchemeHostnameQueryFragment
Method BasicsJust a guide
Status Codes1xx – Informational 2xx – Success3xx – Redirection4xx – Client Error5xx – Server Error
Status Codes Examples100 = Continue102 = Processing200 = OK201 = Created204 = No Content206 = Partial Content301 = Moved Permanently 302 = Found (Moved Temp)307 = Temp Redirect400 = Bad Request401 = Unauthorised402 = Payment Required403 = Forbidden404 = Not Found405 = Method Not Allowed409 = Conflict418 = I’m a teapot450 = Blocked by Windows Parental Controls500 = Internal Server Error501 = Not Implemented
Content TypeProper name: Internet Media TypeAlso known as MIME typeParts: Type, SubType, Optional Parametersx- prefix for nonstandard types or subtypesvnd. prefix for vendor specific subtypesFrowned upon by purists
Content Type Examplestext/plain 			– Plain texttext/xml 			– XML text/html 			– HTML image/png 			– PNG imageaudio/basic 			– Wave audioaudio/mpeg 			– MPEG audio (MP3)video/quicktime 			– Quicktime Videoapplication/pdf 			– Adobe PDF documentapplication/javascript 		– JavaScriptapplication/vnd.ms-powerpoint 	– PowerPoint fileapplication/x-rar-compressed 	– RAR file
HTTP AuthenticationBasic AuthenticationEasy to do, but plain text. Easy to reverse engineer. Less of an issue when used with SSL.Digest AuthenticationHarder to do, still plain text. Hard (impossible?) to reverse engineer because of hashing. NTLM AuthenticationHard to do, Windows specific. Hard (impossible?) to reverse engineer.
Header ExampleRequestHEAD /index.htmlHTTP/1.1 Host: www.example.com ResponseHTTP/1.1 200 OK Date: Mon, 23 May 2005 22:38:34 GMT Server: Apache/1.3.3.7 (Unix) (Red-Hat/Linux) Last-Modified: Wed, 08 Jan 2003 23:11:55 GMT Etag: "3f80f-1b6-3e1cb03b" Accept-Ranges: bytes Content-Length: 438 Connection: close Content-Type: text/html; charset=UTF-8
Lego CatalogueA simple system to store what LEGO’s a person owns. Want toAdd bricksSet bricks status to be in useRemove bricksGet list of bricksCheck if I have enough bricksGet picture of brick
Lego Catalogue URIHTTP ValidREST ValidIntent good
Lego Catalogue URIHTTP ValidREST ValidIntent good
Lego Catalogue URIHTTP ValidREST ValidIntent good
Lego Catalogue URIHTTP ValidREST InvalidIntent bad
Lego Catalogue URIHTTP ValidREST InvalidIntent nightmare
Real Life URI ExampleResource: PhotosWhere:http://farm{farm-id}.static.flickr.com/{server-id}/{id}_{secret}.jpghttp://farm{farm-id}.static.flickr.com/{server-id}/{id}_{secret}_[mstb].jpghttp://farm{farm-id}.static.flickr.com/{server-id}/{id}_{o-secret}_o.(jpg|gif|png)What: JPEG, GIF or PNG (defined in the URL)http://farm1.static.flickr.com/2/1418878_1e92283336_m.jpg
REST Method Style“The big four”
Accidental ServicesAccidental services do not use all methodsSome URL’s offering all of them and others a limited set
Methods Examplehttp://bbddb01/northwind/users[firstname=“rob%”]+ POST = Error + GET = Returns everyone who begins with rob+ PUT = Error+ DELETE = Deletes everyone who begins with robhttp://bbddb01/northwind/users+ we add some input data+ POST = Creates a new user+ GET = Returns everyone who meets criteria+ PUT = Creates/Updates a user (based on data)+ DELETE = Deletes everyone who meets criteria
Methods Examplehttp://bbddb01/northwind/users[firstname=“rob%”]+ POST = Error + PUT = ErrorWhat would the error be?HTTP 400 would be best405 or 500 could also be appropriate
What about actions?GetStoreOpenTime(Location)GET http://lc/stores/{location}/times?state=openRejectDesign(Design)POST http://lc/rejections + form dataPerformBrickCount(Design)POST http://lc/design/124/brickCountGET http://lc/design/124/brickCount/2
GuidelinesDesign to be statelessDesign for resources, not servicesStock quote service vs. A way to work with stock resourcesUse cookies for self-contained state
GuidelinesNaming: Favour nouns over verbsGET /brick/2/deleteDELETE /brick/2Shorter nice URI’s preferred, not requiredDo not change URI’sUse 3xx redirection if needed
GuidelinesGive every resource an IDhttp://lc/brick/1http://lc/project/planned/223More URI’s the better
GuidelinesSupport for multiple data types or representationsFor data use XML and/or JSONPostfixes to define typeGET /brick/2/image.jpgGET /brick/2/image.png
GuidelinesDesign with standards in mind – for example RSS & ATOMCreate should return URI’s not resourcesUse the right HTTP methods for the right actionsYou are on HTTP – use the infrastructure.Proxy, Caching, Etag, Expires
GuidelinesHyperlinks are good<project self=“http://lc/project/753”> <bricksUsed>   <brick ref=“http://lc/brick/234” />    <brick ref=“http://lc/brick/286” /><brick ref=“http://lc/brick/12” /> </bricksUsed> <coloursUsed>   <colour name=“red” code=“ff0000” ref=“http://lc/brick/red”/>  </coloursUsed></project>
GuidelinesOffer paging<bricks self=“http://lc/bricks”> <link rel=“next” ref=“http://lc/bricks?page=20” /> …</bricks>
GuidelinesOffer collections of information<bricks> <brick ref=“http://lc/brick/1” /> <brick ref=“http://lc/brick/2” /><brick ref=“http://lc/brick/3” /></brick><bricks>  <brick ref=“http://lc/brick/1”>    <colour>red</colour> </brick>  <brick ref=“http://lc/brick/2”><colour>red</colour>  </brick>  <brick ref=“http://lc/brick/3”><colour>red</colour>  </brick></brick>
Anti-PatternsUse one HTTP method – like GET for everythingOften called GET or POST TunnellingPass everything in URI’sAssume this is a replacement for SOAP or WS*
Security101Are RESTful services secure?It’s a style, not a technology so that depends on how you implement it.Are you open to SQL injection attacks?When you look at http://bbddb01/northwind/users[firstname=“rob%”], you may think so but you shouldn’t be. Because:The parameter shouldn’t be SQLIf it is SQL, why are you not filtering it?Remember the old rule: Do not trust user inputURI’s are user input
Security102How can I do authentication?It’s built on HTTP, so everything you have for authentication in HTTP is availablePLUSYou could encode your authentication requirements into the input fields
Good ExamplesWCF Data ServicesPreviously called ADO.NET Data Services & AstoriaNerdDinner.comTwitter.comMediaWikiTheir action’s are frowned upon by purists
Benefits of RESTHighly scalableDesigned for HTTP and statelessEasy to consumeNo complex request/response model.No complex XML contractsEasy to understand for you and machinesURI + Method = Intent

More Related Content

PDF
REST in peace @ IPC 2012 in Mainz
PPT
Joseph-Smarr-Plaxo-OSCON-2006
PPT
Plaxo OSCON 2006
PDF
The Case for HTTP/2
ODP
PPT
HTML5 Overview
PDF
HTTP colon slash slash: end of the road? @ CakeFest 2013 in San Francisco
ZIP
Looking into HTML5
REST in peace @ IPC 2012 in Mainz
Joseph-Smarr-Plaxo-OSCON-2006
Plaxo OSCON 2006
The Case for HTTP/2
HTML5 Overview
HTTP colon slash slash: end of the road? @ CakeFest 2013 in San Francisco
Looking into HTML5

What's hot (20)

PPT
Html5 Overview
ODP
A Holistic View of Website Performance
PPT
Joomla security nuggets
PDF
Speed Matters!
PDF
Are Today’s Good Practices… Tomorrow’s Performance Anti-Patterns?
PDF
The Case for HTTP/2 - EpicFEL Sept 2015
PPTX
Internet protocalls & WCF/DReAM
PDF
The Future of the Web: HTML5
PDF
Html 5 in a big nutshell
PDF
HTML5 & Friends
PPTX
Getting the most out of WebPageTest
PPT
Internet Explorer 8 for Developers by Christian Thilmany
PPT
PDF
HTML5 for PHP Developers - IPC
PPTX
Los Angeles HTML5 User Group Meeting Ask the Expert Session
PDF
HTML5 Semantics, Accessibility & Forms [Carsonified HTML5 Online Conference]
PPT
Pragmatics of Declarative Ajax
PPTX
Css, xhtml, javascript
PDF
What the heck is HTML 5?
PPT
PHP Presentation
Html5 Overview
A Holistic View of Website Performance
Joomla security nuggets
Speed Matters!
Are Today’s Good Practices… Tomorrow’s Performance Anti-Patterns?
The Case for HTTP/2 - EpicFEL Sept 2015
Internet protocalls & WCF/DReAM
The Future of the Web: HTML5
Html 5 in a big nutshell
HTML5 & Friends
Getting the most out of WebPageTest
Internet Explorer 8 for Developers by Christian Thilmany
HTML5 for PHP Developers - IPC
Los Angeles HTML5 User Group Meeting Ask the Expert Session
HTML5 Semantics, Accessibility & Forms [Carsonified HTML5 Online Conference]
Pragmatics of Declarative Ajax
Css, xhtml, javascript
What the heck is HTML 5?
PHP Presentation
Ad

Viewers also liked (20)

PPTX
Enterprise Library 5
PPT
Windows Server AppFabric
PPTX
PPT
.NET Reflection
PPTX
Putting the DOT in .NET - Dev/Ops/Test
PPTX
Visual Studio ❤ JavaScript
PPTX
DevConf Survival Guide
PPTX
Lightswitch
PPTX
Windows Server AppFabric Caching - What it is & when you should use it?
PPTX
Win8 architecture for developers
PDF
Summer club
PPTX
Tipos de redes !
PPTX
Thalia
PPT
Dia da mulher
PPT
Biarritz leblon
PDF
Taller # 1 camilo
PPT
Green park apresentação
PDF
One Hundred and One Domatia
PPTX
Cálculo resistencia limitadora a diodo led
Enterprise Library 5
Windows Server AppFabric
.NET Reflection
Putting the DOT in .NET - Dev/Ops/Test
Visual Studio ❤ JavaScript
DevConf Survival Guide
Lightswitch
Windows Server AppFabric Caching - What it is & when you should use it?
Win8 architecture for developers
Summer club
Tipos de redes !
Thalia
Dia da mulher
Biarritz leblon
Taller # 1 camilo
Green park apresentação
One Hundred and One Domatia
Cálculo resistencia limitadora a diodo led
Ad

Similar to RESTful design (20)

PPTX
WWW and HTTP
PPT
Web Scraper Shibuya.pm tech talk #8
PPT
Living in the Cloud: Hosting Data & Apps Using the Google Infrastructure
PPT
RESTful SOA - 中科院暑期讲座
PPT
Introduction To ASP.NET MVC
ODP
Ruby off Rails---rack, sinatra and sequel
ODP
Sword v2 at UKCoRR
PPT
Web services - REST and SOAP
PPT
Living in the Cloud: Hosting Data & Apps Using the Google Infrastructure
PPT
Living in the Cloud: Hosting Data & Apps Using the Google Infrastructure
PDF
Services web RESTful
ODP
Phing - A PHP Build Tool (An Introduction)
PDF
HTTP Caching in Web Application
PDF
HTTP Basics Demo
PPT
GTLAB Installation Tutorial for SciDAC 2009
PDF
Revisiting HTTP/2
ODP
Basic testing with selenium
PPT
Front End Website Optimization
ZIP
GTAC: AtomPub, testing your server implementation
PPT
How the web works june 2010
WWW and HTTP
Web Scraper Shibuya.pm tech talk #8
Living in the Cloud: Hosting Data & Apps Using the Google Infrastructure
RESTful SOA - 中科院暑期讲座
Introduction To ASP.NET MVC
Ruby off Rails---rack, sinatra and sequel
Sword v2 at UKCoRR
Web services - REST and SOAP
Living in the Cloud: Hosting Data & Apps Using the Google Infrastructure
Living in the Cloud: Hosting Data & Apps Using the Google Infrastructure
Services web RESTful
Phing - A PHP Build Tool (An Introduction)
HTTP Caching in Web Application
HTTP Basics Demo
GTLAB Installation Tutorial for SciDAC 2009
Revisiting HTTP/2
Basic testing with selenium
Front End Website Optimization
GTAC: AtomPub, testing your server implementation
How the web works june 2010

More from Robert MacLean (20)

PPTX
Deno ...................................
PPTX
14 things you need to be a successful software developer (v3)
PPTX
OWASP TOP 10
PPTX
Building a µservice with Kotlin, Micronaut & GCP
PPTX
Looking at the Vue
PPTX
Kotlin 101
PPTX
Features of Kotlin I find exciting
PPTX
JavaScript Gotchas
PPTX
The state of testing @ Microsoft
PPTX
What is new in C# 6?
PPTX
A Developer Day 2014 - Durban
PPTX
Agile lessons learned in the Microsoft ALM Rangers
PPTX
Hour of code - Train the trainer
PPTX
Building services for apps on a shoestring budget
PPTX
3 things your app API is doing WRONG
PPTX
PPTX
LightSwitch
PPTX
How to build a Mobile API or HTML 5 app in 5 minutes
PPTX
Protection of Personal Information Bill (POPI)
Deno ...................................
14 things you need to be a successful software developer (v3)
OWASP TOP 10
Building a µservice with Kotlin, Micronaut & GCP
Looking at the Vue
Kotlin 101
Features of Kotlin I find exciting
JavaScript Gotchas
The state of testing @ Microsoft
What is new in C# 6?
A Developer Day 2014 - Durban
Agile lessons learned in the Microsoft ALM Rangers
Hour of code - Train the trainer
Building services for apps on a shoestring budget
3 things your app API is doing WRONG
LightSwitch
How to build a Mobile API or HTML 5 app in 5 minutes
Protection of Personal Information Bill (POPI)

Recently uploaded (20)

PPT
Galois Field Theory of Risk: A Perspective, Protocol, and Mathematical Backgr...
PDF
Consumable AI The What, Why & How for Small Teams.pdf
PPTX
GROUP4NURSINGINFORMATICSREPORT-2 PRESENTATION
PPTX
AI IN MARKETING- PRESENTED BY ANWAR KABIR 1st June 2025.pptx
PDF
“A New Era of 3D Sensing: Transforming Industries and Creating Opportunities,...
PPTX
Training Program for knowledge in solar cell and solar industry
PDF
Auditboard EB SOX Playbook 2023 edition.
PPTX
Configure Apache Mutual Authentication
PDF
AI.gov: A Trojan Horse in the Age of Artificial Intelligence
PDF
CXOs-Are-you-still-doing-manual-DevOps-in-the-age-of-AI.pdf
PDF
Flame analysis and combustion estimation using large language and vision assi...
PDF
The influence of sentiment analysis in enhancing early warning system model f...
PPTX
Internet of Everything -Basic concepts details
PPTX
MuleSoft-Compete-Deck for midddleware integrations
PDF
Comparative analysis of machine learning models for fake news detection in so...
PDF
Transform-Your-Factory-with-AI-Driven-Quality-Engineering.pdf
PPTX
AI-driven Assurance Across Your End-to-end Network With ThousandEyes
PDF
Taming the Chaos: How to Turn Unstructured Data into Decisions
PDF
4 layer Arch & Reference Arch of IoT.pdf
PDF
The-2025-Engineering-Revolution-AI-Quality-and-DevOps-Convergence.pdf
Galois Field Theory of Risk: A Perspective, Protocol, and Mathematical Backgr...
Consumable AI The What, Why & How for Small Teams.pdf
GROUP4NURSINGINFORMATICSREPORT-2 PRESENTATION
AI IN MARKETING- PRESENTED BY ANWAR KABIR 1st June 2025.pptx
“A New Era of 3D Sensing: Transforming Industries and Creating Opportunities,...
Training Program for knowledge in solar cell and solar industry
Auditboard EB SOX Playbook 2023 edition.
Configure Apache Mutual Authentication
AI.gov: A Trojan Horse in the Age of Artificial Intelligence
CXOs-Are-you-still-doing-manual-DevOps-in-the-age-of-AI.pdf
Flame analysis and combustion estimation using large language and vision assi...
The influence of sentiment analysis in enhancing early warning system model f...
Internet of Everything -Basic concepts details
MuleSoft-Compete-Deck for midddleware integrations
Comparative analysis of machine learning models for fake news detection in so...
Transform-Your-Factory-with-AI-Driven-Quality-Engineering.pdf
AI-driven Assurance Across Your End-to-end Network With ThousandEyes
Taming the Chaos: How to Turn Unstructured Data into Decisions
4 layer Arch & Reference Arch of IoT.pdf
The-2025-Engineering-Revolution-AI-Quality-and-DevOps-Convergence.pdf

RESTful design

  • 1. Understanding REST and designing for itRESTful Design
  • 2. Robert MacLeanwww.sadev.co.za@rmacleanBB&D ATCIntroductionHTTP BasicsURI’sMethodsStatus CodesContent TypeAuthenticationURI PlanningPatternsStyleAccidental ServicesExamplesActionsGuidelinesAnti-PatternsSecurityWrap UpAbout meAgendaWelcome
  • 3. RESTAcronym? Representational State Transfer Source?Came about in 2000 doctoral dissertation of Roy Fielding
  • 4. What is it?ROA – Resource Orientated ArchitectureWOA – Web Orientated ArchitectureThanks Gartner for another TLA It is a styleNOT APIInterfaceOfficial StandardA drop in replacement for SOAP
  • 5. Benefits of RESTHighly scalableDesigned for HTTPEasy to consume & produceNo complex request/response model.No complex XML contractsEasy to understand for you and machinesURI + Method = Intent
  • 6. HTTP BasicsREST builds on HTTP so you need to know HTTPHTTP is not HTMLHTTP is statelessHTTPURIHeaderhttp://www.sadev.co.zaMethodGETStatus Code200Content Typetext/plainBodytext
  • 9. Status Codes1xx – Informational 2xx – Success3xx – Redirection4xx – Client Error5xx – Server Error
  • 10. Status Codes Examples100 = Continue102 = Processing200 = OK201 = Created204 = No Content206 = Partial Content301 = Moved Permanently 302 = Found (Moved Temp)307 = Temp Redirect400 = Bad Request401 = Unauthorised402 = Payment Required403 = Forbidden404 = Not Found405 = Method Not Allowed409 = Conflict418 = I’m a teapot450 = Blocked by Windows Parental Controls500 = Internal Server Error501 = Not Implemented
  • 11. Content TypeProper name: Internet Media TypeAlso known as MIME typeParts: Type, SubType, Optional Parametersx- prefix for nonstandard types or subtypesvnd. prefix for vendor specific subtypesFrowned upon by purists
  • 12. Content Type Examplestext/plain – Plain texttext/xml – XML text/html – HTML image/png – PNG imageaudio/basic – Wave audioaudio/mpeg – MPEG audio (MP3)video/quicktime – Quicktime Videoapplication/pdf – Adobe PDF documentapplication/javascript – JavaScriptapplication/vnd.ms-powerpoint – PowerPoint fileapplication/x-rar-compressed – RAR file
  • 13. HTTP AuthenticationBasic AuthenticationEasy to do, but plain text. Easy to reverse engineer. Less of an issue when used with SSL.Digest AuthenticationHarder to do, still plain text. Hard (impossible?) to reverse engineer because of hashing. NTLM AuthenticationHard to do, Windows specific. Hard (impossible?) to reverse engineer.
  • 14. Header ExampleRequestHEAD /index.htmlHTTP/1.1 Host: www.example.com ResponseHTTP/1.1 200 OK Date: Mon, 23 May 2005 22:38:34 GMT Server: Apache/1.3.3.7 (Unix) (Red-Hat/Linux) Last-Modified: Wed, 08 Jan 2003 23:11:55 GMT Etag: "3f80f-1b6-3e1cb03b" Accept-Ranges: bytes Content-Length: 438 Connection: close Content-Type: text/html; charset=UTF-8
  • 15. Lego CatalogueA simple system to store what LEGO’s a person owns. Want toAdd bricksSet bricks status to be in useRemove bricksGet list of bricksCheck if I have enough bricksGet picture of brick
  • 16. Lego Catalogue URIHTTP ValidREST ValidIntent good
  • 17. Lego Catalogue URIHTTP ValidREST ValidIntent good
  • 18. Lego Catalogue URIHTTP ValidREST ValidIntent good
  • 19. Lego Catalogue URIHTTP ValidREST InvalidIntent bad
  • 20. Lego Catalogue URIHTTP ValidREST InvalidIntent nightmare
  • 21. Real Life URI ExampleResource: PhotosWhere:http://farm{farm-id}.static.flickr.com/{server-id}/{id}_{secret}.jpghttp://farm{farm-id}.static.flickr.com/{server-id}/{id}_{secret}_[mstb].jpghttp://farm{farm-id}.static.flickr.com/{server-id}/{id}_{o-secret}_o.(jpg|gif|png)What: JPEG, GIF or PNG (defined in the URL)http://farm1.static.flickr.com/2/1418878_1e92283336_m.jpg
  • 23. Accidental ServicesAccidental services do not use all methodsSome URL’s offering all of them and others a limited set
  • 24. Methods Examplehttp://bbddb01/northwind/users[firstname=“rob%”]+ POST = Error + GET = Returns everyone who begins with rob+ PUT = Error+ DELETE = Deletes everyone who begins with robhttp://bbddb01/northwind/users+ we add some input data+ POST = Creates a new user+ GET = Returns everyone who meets criteria+ PUT = Creates/Updates a user (based on data)+ DELETE = Deletes everyone who meets criteria
  • 25. Methods Examplehttp://bbddb01/northwind/users[firstname=“rob%”]+ POST = Error + PUT = ErrorWhat would the error be?HTTP 400 would be best405 or 500 could also be appropriate
  • 26. What about actions?GetStoreOpenTime(Location)GET http://lc/stores/{location}/times?state=openRejectDesign(Design)POST http://lc/rejections + form dataPerformBrickCount(Design)POST http://lc/design/124/brickCountGET http://lc/design/124/brickCount/2
  • 27. GuidelinesDesign to be statelessDesign for resources, not servicesStock quote service vs. A way to work with stock resourcesUse cookies for self-contained state
  • 28. GuidelinesNaming: Favour nouns over verbsGET /brick/2/deleteDELETE /brick/2Shorter nice URI’s preferred, not requiredDo not change URI’sUse 3xx redirection if needed
  • 29. GuidelinesGive every resource an IDhttp://lc/brick/1http://lc/project/planned/223More URI’s the better
  • 30. GuidelinesSupport for multiple data types or representationsFor data use XML and/or JSONPostfixes to define typeGET /brick/2/image.jpgGET /brick/2/image.png
  • 31. GuidelinesDesign with standards in mind – for example RSS & ATOMCreate should return URI’s not resourcesUse the right HTTP methods for the right actionsYou are on HTTP – use the infrastructure.Proxy, Caching, Etag, Expires
  • 32. GuidelinesHyperlinks are good<project self=“http://lc/project/753”> <bricksUsed> <brick ref=“http://lc/brick/234” /> <brick ref=“http://lc/brick/286” /><brick ref=“http://lc/brick/12” /> </bricksUsed> <coloursUsed> <colour name=“red” code=“ff0000” ref=“http://lc/brick/red”/> </coloursUsed></project>
  • 33. GuidelinesOffer paging<bricks self=“http://lc/bricks”> <link rel=“next” ref=“http://lc/bricks?page=20” /> …</bricks>
  • 34. GuidelinesOffer collections of information<bricks> <brick ref=“http://lc/brick/1” /> <brick ref=“http://lc/brick/2” /><brick ref=“http://lc/brick/3” /></brick><bricks> <brick ref=“http://lc/brick/1”> <colour>red</colour> </brick> <brick ref=“http://lc/brick/2”><colour>red</colour> </brick> <brick ref=“http://lc/brick/3”><colour>red</colour> </brick></brick>
  • 35. Anti-PatternsUse one HTTP method – like GET for everythingOften called GET or POST TunnellingPass everything in URI’sAssume this is a replacement for SOAP or WS*
  • 36. Security101Are RESTful services secure?It’s a style, not a technology so that depends on how you implement it.Are you open to SQL injection attacks?When you look at http://bbddb01/northwind/users[firstname=“rob%”], you may think so but you shouldn’t be. Because:The parameter shouldn’t be SQLIf it is SQL, why are you not filtering it?Remember the old rule: Do not trust user inputURI’s are user input
  • 37. Security102How can I do authentication?It’s built on HTTP, so everything you have for authentication in HTTP is availablePLUSYou could encode your authentication requirements into the input fields
  • 38. Good ExamplesWCF Data ServicesPreviously called ADO.NET Data Services & AstoriaNerdDinner.comTwitter.comMediaWikiTheir action’s are frowned upon by purists
  • 39. Benefits of RESTHighly scalableDesigned for HTTP and statelessEasy to consumeNo complex request/response model.No complex XML contractsEasy to understand for you and machinesURI + Method = Intent