SlideShare a Scribd company logo
1 of 39
Understanding REST and designing for it RESTful Design
Robert MacLean www.sadev.co.za @rmaclean BB&D ATC Introduction HTTP Basics URI’s Methods Status Codes Content Type Authentication URI Planning Patterns Style Accidental Services Examples Actions Guidelines Anti-Patterns Security Wrap Up About me Agenda Welcome
REST Acronym?  Representational State Transfer  Source? Came about in 2000 doctoral dissertation of Roy Fielding
What is it? ROA – Resource Orientated Architecture WOA – Web Orientated Architecture Thanks Gartner for another TLA  It is a style NOT  API Interface Official Standard A drop in replacement for SOAP
Benefits of REST Highly scalable Designed for HTTP Easy to consume & produce No complex request/response model. No complex XML contracts Easy to understand for you and machines URI + Method = Intent
HTTP Basics REST builds on HTTP so you need to know HTTP HTTP is not HTML HTTP is stateless HTTP URI Header http://www.sadev.co.za Method GET Status Code 200 Content Type text/plain Body text
URI Basics Hostname Scheme Query http://www.sadev.co.za/users/1/contact http://www.sadev.co.za?user=1&action=contact http://rob:pass@bbd.co.za:8044 https://bbd.co.za/index.html#about Query Hostname Scheme Userinfo Hostname Port Scheme Scheme Hostname Query Fragment
Method Basics Just a guide
Status Codes 1xx – Informational  2xx – Success 3xx – Redirection 4xx – Client Error 5xx – Server Error
Status Codes Examples 100 = Continue 102 = Processing 200 = OK 201 = Created 204 = No Content 206 = Partial Content 301 = Moved Permanently  302 = Found (Moved Temp) 307 = Temp Redirect 400 = Bad Request 401 = Unauthorised 402 = Payment Required 403 = Forbidden 404 = Not Found 405 = Method Not Allowed 409 = Conflict 418 = I’m a teapot 450 = Blocked by Windows Parental Controls 500 = Internal Server Error 501 = Not Implemented
Content Type Proper name: Internet Media Type Also known as MIME type Parts: Type, SubType, Optional Parameters x- prefix for nonstandard types or subtypes vnd. prefix for vendor specific subtypes Frowned upon by purists
Content Type Examples text/plain 			– Plain text text/xml 			– XML  text/html 			– HTML  image/png 			– PNG image audio/basic 			– Wave audio audio/mpeg 			– MPEG audio (MP3) video/quicktime 			– Quicktime Video application/pdf 			– Adobe PDF document application/javascript 		– JavaScript application/vnd.ms-powerpoint 	– PowerPoint file application/x-rar-compressed 	– RAR file
HTTP Authentication Basic Authentication Easy to do, but plain text. Easy to reverse engineer. Less of an issue when used with SSL. Digest Authentication Harder to do, still plain text. Hard (impossible?) to reverse engineer because of hashing.  NTLM Authentication Hard to do, Windows specific. Hard (impossible?) to reverse engineer.
Header Example Request HEAD /index.html HTTP/1.1  Host: www.example.com  Response HTTP/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 Catalogue A simple system to store what LEGO’s a person owns.  Want to Add bricks Set bricks status to be in use Remove bricks Get list of bricks Check if I have enough bricks Get picture of brick
Lego Catalogue URI HTTP Valid REST Valid Intent good
Lego Catalogue URI HTTP Valid REST Valid Intent good
Lego Catalogue URI HTTP Valid REST Valid Intent good
Lego Catalogue URI HTTP Valid REST Invalid Intent bad
Lego Catalogue URI HTTP Valid REST Invalid Intent nightmare
Real Life URI Example Resource: Photos Where: http://farm{farm-id}.static.flickr.com/{server-id}/{id}_{secret}.jpg http://farm{farm-id}.static.flickr.com/{server-id}/{id}_{secret}_[mstb].jpg http://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 Services Accidental services do not use all methods Some URL’s offering all of them and others a limited set
Methods Example http://bbddb01/northwind/users[firstname=“rob%”] + POST = Error  + GET = Returns everyone who begins with rob + PUT = Error + DELETE = Deletes everyone who begins with rob http://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 Example http://bbddb01/northwind/users[firstname=“rob%”] + POST = Error  + PUT = Error What would the error be? HTTP 400 would be best 405 or 500 could also be appropriate
What about actions? GetStoreOpenTime(Location) GET http://lc/stores/{location}/times?state=open RejectDesign(Design) POST http://lc/rejections + form data PerformBrickCount(Design) POST http://lc/design/124/brickCount GET http://lc/design/124/brickCount/2
Guidelines Design to be stateless Design for resources, not services Stock quote service vs. A way to work with stock resources Use cookies for self-contained state
Guidelines Naming: Favour nouns over verbs GET /brick/2/delete DELETE /brick/2 Shorter nice URI’s preferred, not required Do not change URI’s Use 3xx redirection if needed
Guidelines Give every resource an ID http://lc/brick/1 http://lc/project/planned/223 More URI’s the better
Guidelines Support for multiple data types or representations For data use XML and/or JSON Postfixes to define type GET /brick/2/image.jpg GET /brick/2/image.png
Guidelines Design with standards in mind – for example RSS & ATOM Create should return URI’s not resources Use the right HTTP methods for the right actions You are on HTTP – use the infrastructure. Proxy, Caching, Etag, Expires
Guidelines Hyperlinks 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>
Guidelines Offer paging <bricks self=“http://lc/bricks”>  <link rel=“next” ref=“http://lc/bricks?page=20” />  … </bricks>
Guidelines Offer 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-Patterns Use one HTTP method – like GET for everything Often called GET or POST Tunnelling Pass everything in URI’s Assume this is a replacement for SOAP or WS*
Security101 Are 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 SQL If it is SQL, why are you not filtering it? Remember the old rule: Do not trust user input URI’s are user input
Security102 How can I do authentication? It’s built on HTTP, so everything you have for authentication in HTTP is available PLUS You could encode your authentication requirements into the input fields
Good Examples WCF Data Services Previously called ADO.NET Data Services & Astoria NerdDinner.com Twitter.com MediaWiki Their action’s are frowned upon by purists
Benefits of REST Highly scalable Designed for HTTP and stateless Easy to consume No complex request/response model. No complex XML contracts Easy to understand for you and machines URI + Method = Intent

More Related Content

What's hot

Joomla security nuggets
Joomla security nuggetsJoomla security nuggets
Joomla security nuggets
guestbd1cdca
 
HTML5 for PHP Developers - IPC
HTML5 for PHP Developers - IPCHTML5 for PHP Developers - IPC
HTML5 for PHP Developers - IPC
Mayflower GmbH
 

What's hot (20)

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

Viewers also liked

Win8 architecture for developers
Win8 architecture for developersWin8 architecture for developers
Win8 architecture for developers
Robert MacLean
 
Summer club
Summer clubSummer club
Summer club
Mad Mary
 
Dia da mulher
Dia da mulherDia da mulher
Dia da mulher
eecdda
 
Biarritz leblon
Biarritz leblonBiarritz leblon
Biarritz leblon
Mad Mary
 
Taller # 1 camilo
Taller # 1 camiloTaller # 1 camilo
Taller # 1 camilo
kamilo1997
 
Green park apresentação
Green park apresentaçãoGreen park apresentação
Green park apresentação
Mad Mary
 
One Hundred and One Domatia
One Hundred and One DomatiaOne Hundred and One Domatia
One Hundred and One Domatia
Amy Luckhurst
 

Viewers also liked (20)

Enterprise Library 5
Enterprise Library 5Enterprise Library 5
Enterprise Library 5
 
Windows Server AppFabric
Windows Server AppFabricWindows Server AppFabric
Windows Server AppFabric
 
Sikuli
SikuliSikuli
Sikuli
 
.NET Reflection
.NET Reflection.NET Reflection
.NET Reflection
 
Putting the DOT in .NET - Dev/Ops/Test
Putting the DOT in .NET - Dev/Ops/TestPutting the DOT in .NET - Dev/Ops/Test
Putting the DOT in .NET - Dev/Ops/Test
 
Visual Studio ❤ JavaScript
Visual Studio ❤ JavaScriptVisual Studio ❤ JavaScript
Visual Studio ❤ JavaScript
 
DevConf Survival Guide
DevConf Survival GuideDevConf Survival Guide
DevConf Survival Guide
 
Lightswitch
LightswitchLightswitch
Lightswitch
 
Windows Server AppFabric Caching - What it is & when you should use it?
Windows Server AppFabric Caching - What it is & when you should use it?Windows Server AppFabric Caching - What it is & when you should use it?
Windows Server AppFabric Caching - What it is & when you should use it?
 
Win8 architecture for developers
Win8 architecture for developersWin8 architecture for developers
Win8 architecture for developers
 
Summer club
Summer clubSummer club
Summer club
 
Ti
TiTi
Ti
 
Tipos de redes !
Tipos de redes !Tipos de redes !
Tipos de redes !
 
Thalia
ThaliaThalia
Thalia
 
Dia da mulher
Dia da mulherDia da mulher
Dia da mulher
 
Biarritz leblon
Biarritz leblonBiarritz leblon
Biarritz leblon
 
Taller # 1 camilo
Taller # 1 camiloTaller # 1 camilo
Taller # 1 camilo
 
Green park apresentação
Green park apresentaçãoGreen park apresentação
Green park apresentação
 
One Hundred and One Domatia
One Hundred and One DomatiaOne Hundred and One Domatia
One Hundred and One Domatia
 
Cálculo resistencia limitadora a diodo led
Cálculo resistencia limitadora a diodo ledCálculo resistencia limitadora a diodo led
Cálculo resistencia limitadora a diodo led
 

Similar to RESTful design

Web Scraper Shibuya.pm tech talk #8
Web Scraper Shibuya.pm tech talk #8Web Scraper Shibuya.pm tech talk #8
Web Scraper Shibuya.pm tech talk #8
Tatsuhiko Miyagawa
 
RESTful SOA - 中科院暑期讲座
RESTful SOA - 中科院暑期讲座RESTful SOA - 中科院暑期讲座
RESTful SOA - 中科院暑期讲座
Li Yi
 
Services web RESTful
Services web RESTfulServices web RESTful
Services web RESTful
goldoraf
 
GTLAB Installation Tutorial for SciDAC 2009
GTLAB Installation Tutorial for SciDAC 2009GTLAB Installation Tutorial for SciDAC 2009
GTLAB Installation Tutorial for SciDAC 2009
marpierc
 
GTAC: AtomPub, testing your server implementation
GTAC: AtomPub, testing your server implementationGTAC: AtomPub, testing your server implementation
GTAC: AtomPub, testing your server implementation
David Calavera
 

Similar to RESTful design (20)

WWW and HTTP
WWW and HTTPWWW and HTTP
WWW and HTTP
 
Web Scraper Shibuya.pm tech talk #8
Web Scraper Shibuya.pm tech talk #8Web Scraper Shibuya.pm tech talk #8
Web Scraper Shibuya.pm tech talk #8
 
Living in the Cloud: Hosting Data & Apps Using the Google Infrastructure
Living in the Cloud: Hosting Data & Apps Using the Google InfrastructureLiving in the Cloud: Hosting Data & Apps Using the Google Infrastructure
Living in the Cloud: Hosting Data & Apps Using the Google Infrastructure
 
RESTful SOA - 中科院暑期讲座
RESTful SOA - 中科院暑期讲座RESTful SOA - 中科院暑期讲座
RESTful SOA - 中科院暑期讲座
 
Introduction To ASP.NET MVC
Introduction To ASP.NET MVCIntroduction To ASP.NET MVC
Introduction To ASP.NET MVC
 
Ruby off Rails---rack, sinatra and sequel
Ruby off Rails---rack, sinatra and sequelRuby off Rails---rack, sinatra and sequel
Ruby off Rails---rack, sinatra and sequel
 
Sword v2 at UKCoRR
Sword v2 at UKCoRRSword v2 at UKCoRR
Sword v2 at UKCoRR
 
Web services - REST and SOAP
Web services - REST and SOAPWeb services - REST and SOAP
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 InfrastructureLiving in the Cloud: Hosting Data & Apps Using the Google Infrastructure
Living in the Cloud: Hosting Data & Apps Using the Google Infrastructure
 
Living in the Cloud: Hosting Data & Apps Using the Google Infrastructure
Living in the Cloud: Hosting Data & Apps Using the Google InfrastructureLiving in the Cloud: Hosting Data & Apps Using the Google Infrastructure
Living in the Cloud: Hosting Data & Apps Using the Google Infrastructure
 
Services web RESTful
Services web RESTfulServices web RESTful
Services web RESTful
 
Phing - A PHP Build Tool (An Introduction)
Phing - A PHP Build Tool (An Introduction)Phing - A PHP Build Tool (An Introduction)
Phing - A PHP Build Tool (An Introduction)
 
HTTP Caching in Web Application
HTTP Caching in Web ApplicationHTTP Caching in Web Application
HTTP Caching in Web Application
 
HTTP Basics Demo
HTTP Basics DemoHTTP Basics Demo
HTTP Basics Demo
 
GTLAB Installation Tutorial for SciDAC 2009
GTLAB Installation Tutorial for SciDAC 2009GTLAB Installation Tutorial for SciDAC 2009
GTLAB Installation Tutorial for SciDAC 2009
 
Revisiting HTTP/2
Revisiting HTTP/2Revisiting HTTP/2
Revisiting HTTP/2
 
Basic testing with selenium
Basic testing with seleniumBasic testing with selenium
Basic testing with selenium
 
Front End Website Optimization
Front End Website OptimizationFront End Website Optimization
Front End Website Optimization
 
GTAC: AtomPub, testing your server implementation
GTAC: AtomPub, testing your server implementationGTAC: AtomPub, testing your server implementation
GTAC: AtomPub, testing your server implementation
 
How the web works june 2010
How the web works june 2010How the web works june 2010
How the web works june 2010
 

More from Robert MacLean

More from Robert MacLean (20)

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

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 

RESTful design

  • 1. Understanding REST and designing for it RESTful Design
  • 2. Robert MacLean www.sadev.co.za @rmaclean BB&D ATC Introduction HTTP Basics URI’s Methods Status Codes Content Type Authentication URI Planning Patterns Style Accidental Services Examples Actions Guidelines Anti-Patterns Security Wrap Up About me Agenda Welcome
  • 3. REST Acronym? Representational State Transfer Source? Came about in 2000 doctoral dissertation of Roy Fielding
  • 4. What is it? ROA – Resource Orientated Architecture WOA – Web Orientated Architecture Thanks Gartner for another TLA  It is a style NOT API Interface Official Standard A drop in replacement for SOAP
  • 5. Benefits of REST Highly scalable Designed for HTTP Easy to consume & produce No complex request/response model. No complex XML contracts Easy to understand for you and machines URI + Method = Intent
  • 6. HTTP Basics REST builds on HTTP so you need to know HTTP HTTP is not HTML HTTP is stateless HTTP URI Header http://www.sadev.co.za Method GET Status Code 200 Content Type text/plain Body text
  • 7. URI Basics Hostname Scheme Query http://www.sadev.co.za/users/1/contact http://www.sadev.co.za?user=1&action=contact http://rob:pass@bbd.co.za:8044 https://bbd.co.za/index.html#about Query Hostname Scheme Userinfo Hostname Port Scheme Scheme Hostname Query Fragment
  • 9. Status Codes 1xx – Informational 2xx – Success 3xx – Redirection 4xx – Client Error 5xx – Server Error
  • 10. Status Codes Examples 100 = Continue 102 = Processing 200 = OK 201 = Created 204 = No Content 206 = Partial Content 301 = Moved Permanently 302 = Found (Moved Temp) 307 = Temp Redirect 400 = Bad Request 401 = Unauthorised 402 = Payment Required 403 = Forbidden 404 = Not Found 405 = Method Not Allowed 409 = Conflict 418 = I’m a teapot 450 = Blocked by Windows Parental Controls 500 = Internal Server Error 501 = Not Implemented
  • 11. Content Type Proper name: Internet Media Type Also known as MIME type Parts: Type, SubType, Optional Parameters x- prefix for nonstandard types or subtypes vnd. prefix for vendor specific subtypes Frowned upon by purists
  • 12. Content Type Examples text/plain – Plain text text/xml – XML text/html – HTML image/png – PNG image audio/basic – Wave audio audio/mpeg – MPEG audio (MP3) video/quicktime – Quicktime Video application/pdf – Adobe PDF document application/javascript – JavaScript application/vnd.ms-powerpoint – PowerPoint file application/x-rar-compressed – RAR file
  • 13. HTTP Authentication Basic Authentication Easy to do, but plain text. Easy to reverse engineer. Less of an issue when used with SSL. Digest Authentication Harder to do, still plain text. Hard (impossible?) to reverse engineer because of hashing. NTLM Authentication Hard to do, Windows specific. Hard (impossible?) to reverse engineer.
  • 14. Header Example Request HEAD /index.html HTTP/1.1 Host: www.example.com Response HTTP/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 Catalogue A simple system to store what LEGO’s a person owns. Want to Add bricks Set bricks status to be in use Remove bricks Get list of bricks Check if I have enough bricks Get picture of brick
  • 16. Lego Catalogue URI HTTP Valid REST Valid Intent good
  • 17. Lego Catalogue URI HTTP Valid REST Valid Intent good
  • 18. Lego Catalogue URI HTTP Valid REST Valid Intent good
  • 19. Lego Catalogue URI HTTP Valid REST Invalid Intent bad
  • 20. Lego Catalogue URI HTTP Valid REST Invalid Intent nightmare
  • 21. Real Life URI Example Resource: Photos Where: http://farm{farm-id}.static.flickr.com/{server-id}/{id}_{secret}.jpg http://farm{farm-id}.static.flickr.com/{server-id}/{id}_{secret}_[mstb].jpg http://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
  • 22. REST Method Style “The big four”
  • 23. Accidental Services Accidental services do not use all methods Some URL’s offering all of them and others a limited set
  • 24. Methods Example http://bbddb01/northwind/users[firstname=“rob%”] + POST = Error + GET = Returns everyone who begins with rob + PUT = Error + DELETE = Deletes everyone who begins with rob http://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 Example http://bbddb01/northwind/users[firstname=“rob%”] + POST = Error + PUT = Error What would the error be? HTTP 400 would be best 405 or 500 could also be appropriate
  • 26. What about actions? GetStoreOpenTime(Location) GET http://lc/stores/{location}/times?state=open RejectDesign(Design) POST http://lc/rejections + form data PerformBrickCount(Design) POST http://lc/design/124/brickCount GET http://lc/design/124/brickCount/2
  • 27. Guidelines Design to be stateless Design for resources, not services Stock quote service vs. A way to work with stock resources Use cookies for self-contained state
  • 28. Guidelines Naming: Favour nouns over verbs GET /brick/2/delete DELETE /brick/2 Shorter nice URI’s preferred, not required Do not change URI’s Use 3xx redirection if needed
  • 29. Guidelines Give every resource an ID http://lc/brick/1 http://lc/project/planned/223 More URI’s the better
  • 30. Guidelines Support for multiple data types or representations For data use XML and/or JSON Postfixes to define type GET /brick/2/image.jpg GET /brick/2/image.png
  • 31. Guidelines Design with standards in mind – for example RSS & ATOM Create should return URI’s not resources Use the right HTTP methods for the right actions You are on HTTP – use the infrastructure. Proxy, Caching, Etag, Expires
  • 32. Guidelines Hyperlinks 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. Guidelines Offer paging <bricks self=“http://lc/bricks”> <link rel=“next” ref=“http://lc/bricks?page=20” /> … </bricks>
  • 34. Guidelines Offer 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-Patterns Use one HTTP method – like GET for everything Often called GET or POST Tunnelling Pass everything in URI’s Assume this is a replacement for SOAP or WS*
  • 36. Security101 Are 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 SQL If it is SQL, why are you not filtering it? Remember the old rule: Do not trust user input URI’s are user input
  • 37. Security102 How can I do authentication? It’s built on HTTP, so everything you have for authentication in HTTP is available PLUS You could encode your authentication requirements into the input fields
  • 38. Good Examples WCF Data Services Previously called ADO.NET Data Services & Astoria NerdDinner.com Twitter.com MediaWiki Their action’s are frowned upon by purists
  • 39. Benefits of REST Highly scalable Designed for HTTP and stateless Easy to consume No complex request/response model. No complex XML contracts Easy to understand for you and machines URI + Method = Intent