SlideShare a Scribd company logo
GET




Gábor Török @ EPAM/Szeged
   Introduction, overview



   Best practices



   Java support
   Roy T Fielding, PhD dissertation, 2000

   Main characteristics
    ◦   Client-server
    ◦   Stateless
    ◦   Caching
    ◦   Layered architecture
    ◦   Code on demand
    ◦   URIs
Richardson’s Maturity Model




                              Image courtesy of
                              Martin Fowler
   Plain Old XML (over HTTP)

   One URI, one method
POST /appointmentService HTTP/1.1

<openSlotRequest date="2010-01-04"
                 doctor="mjones"/>
Level 0: POX response

HTTP/1.1 200 OK

<openSlotList>
   <slot start="1400" end="1450">
      <doctor id="mjones"/>
   </slot>
   <slot start="1600" end="1650">
      <doctor id="mjones"/>
   </slot>
</openSlotList>
POST /appointmentService HTTP/1.1

<appointmentRequest>
   <slot doctor="mjones" start="1400"
         end="1450"/>
   <patient id="jsmith"/>
</appointmentRequest>
Level 0: POX response

HTTP/1.1 200 OK

<appointment>
   <slot doctor="mjones" start="1400"
         end="1450"/>
   <patient id="jsmith"/>
</appointment>
Many URIs, one method
POST /doctors/mjones HTTP/1.1

<openSlotRequest date="2010-01-04"/>
Level 1: Resources response

HTTP/1.1 200 OK

<openSlotList>
   <slot id="1234" doctor="mjones"
         start="1400" end="1450"/>
   <slot id="5678" doctor="mjones"
         start="1600" end="1650"/>
</openSlotList>
POST /slots/1234 HTTP/1.1

<appointmentRequest>
   <patient id="jsmith"/>
</appointmentRequest>
Level 1: Resources response

HTTP/1.1 200 OK

<appointment id="2468">
   <slot id="1234" doctor="mjones"
         start="1400" end="1450”/>
   <patient id="jsmith"/>
</appointment>
   Many URIs, many (HTTP) methods



   This is what most call REST



   Best practices follow
GET
/doctors/mjones/slots?date=20100104&s
tatus=open HTTP/1.1
Level 2: Verbs response

HTTP/1.1 200 OK

<openSlotList>
   <slot id="1234" doctor="mjones"
         start="1400" end="1450"/>
   <slot id="5678" doctor="mjones"
         start="1600" end="1650"/>
</openSlotList>
POST /slots/1234 HTTP/1.1

<appointmentRequest>
   <patient id="jsmith"/>
</appointmentRequest>
Level 2: Verbs response

HTTP/1.1 200 OK

<appointment id="2468">
   <slot id="1234" doctor="mjones"
         start="1400" end="1450”/>
   <patient id="jsmith"/>
</appointment>
W3: „Cool URIs don’t change”
                       vs
Roy Fielding: „A REST API must not define fixed
        resource names or hierarchies”

   HATEOAS & self-descriptive messages

   Problems: people’s awareness, tools
Level 3: Hypermedia response
HTTP/1.1 200 OK

<openSlotList>
  <slot id="1234" doctor="mjones”
        start="1400" end="1450">
    <link rel="/linkrels/slot/book"
          uri="/slots/1234"/>
  </slot>
     …
</openSlotList>
Level 3: Hypermedia response
HTTP/1.1 201 Created
Location: http://.../slots/1234/appointment

<appointment>
  <slot id="1234" …/>
    <patient id="jsmith"/>
    <link rel="/linkrels/appointment/cancel"
          uri="/slots/1234/appointment"/>
    <link rel="self"
          uri="/slots/1234/appointment"/>
</appointment>
Solves interop problems    WSDL contract
                             Strong typing
                             Client- and server
                             bindings
                             Operations (i.e. verbs)
WS-* support (Security,    GETing/POSTing an XML
AtomicTransaction, etc.)

Many proxies block PUT     Non-intuitive


                      Level 0
   Resources vs actions



getTickets vs /tickets
getMusemTickets vs /tickets?type=museum
Plural + ID
CRUD-style operations
Concrete not abstract names

Resource      GET            POST         PUT            DELETE
/tickets      List tickets   Create a     Bulk update    Delete all
                             new ticket                  tickets
/tickets/123 Get the         Error        Update a       Delete a
             details of                   given ticket   given ticket
             one ticket
   http://api.company.com/cafe/v1



   Major rev only



   Numbers, not nicknames, dates, etc.
   HTTP status codes

                    200
              403
                          500
        503     204               200 400
        201           400
                                   500
                404       405
          401



   Short description
   Pointer to more information
HTTP Status Code: 401

{ "status" : "401",
  "message":"Authenticate",
  "code": 12345,
  "more info":
http://developers.company.com/docs/er
rors/12345 }
   Ways to differentiate:

       /tickets/123.json
       /tickets/123?format=json
       Accept: application/json

   Bonus: application/company.v1+json
   Pagination:
       /tickets?offset=50&limit=25

   Partial response:
       /tickets?fields=date,location

   Use defaults (documentation!)
   Session management – REST is stateless



   Caching – it’s very much encouraged!



   What if nouns are not appropriate – use verbs
   Security – preferred is OAuth, lot of
    Basic/Digest over HTTPS in practice

   Subdomains:
    ◦ api
    ◦ developers for SDK


   Clean REST
   JSR 311: Java API for RESTful Web Services

 Annotation-driven
@GET, @Path, @PathParam, @Consumes

 Implementations
Jersey, Restlet, RESTeasy, Apache CXF

   Jax-rs-hateoas
jax-rs example.java
   Spring MVC application essentially

 Annotation-driven + XML configuration
@RequestMapping et al. + view
resolvers, message converters, et al.

   spring-hateoas
spring mvc example.java
   CRUD for JPA-entities using REST semantics

   @RestResource

   Pagination and sorting support

   spring-hateoas
spring data rest.java
   Roy Fielding’s dissertation

   REST in Practice from O’Reilly

   Apigee blog & video tutorials

   Articles, forums
   Levels of REST – REST ≠ CRUD



   Consistent view of best practices



   Java support
   Has been in the industry since late ’90s

   Has been @EPAM since 2009, acted as a Dev
    Lead/PM, now Solutions Architect

   Has mobile + enterprise background

             gabor.i.torok@gmail.com
Rest in practice

More Related Content

Viewers also liked

บุคคลสำคัญของบางกอก
บุคคลสำคัญของบางกอกบุคคลสำคัญของบางกอก
บุคคลสำคัญของบางกอก
nearary
 
Pinterest Presentation for Small Businesses
Pinterest Presentation for Small BusinessesPinterest Presentation for Small Businesses
Pinterest Presentation for Small Businesses
Chena Tucker
 
Creative Marketing
Creative MarketingCreative Marketing
Creative MarketingChena Tucker
 
Blog de pol
Blog de polBlog de pol
Blog de polpolpoma
 
Blog de pol
Blog de polBlog de pol
Blog de polpolpoma
 
A Marketing Fable
A Marketing FableA Marketing Fable
A Marketing Fable
Actis Wunderman
 
บุคคลสำคัญของบางกอก
บุคคลสำคัญของบางกอกบุคคลสำคัญของบางกอก
บุคคลสำคัญของบางกอกnearary
 
Blog de pol
Blog de polBlog de pol
Blog de polpolpoma
 
VinaWealth Stock Investing Basics
VinaWealth Stock Investing BasicsVinaWealth Stock Investing Basics
VinaWealth Stock Investing Basics
Thai Nguyen
 
5 Ways to Spring Clean Your Credit Report
5 Ways to Spring Clean Your Credit Report5 Ways to Spring Clean Your Credit Report
5 Ways to Spring Clean Your Credit Report
Chena Tucker
 
Как выгодно продать интерактивное агентство (РИФ+КИБ 2010)
Как выгодно продать интерактивное агентство (РИФ+КИБ 2010)Как выгодно продать интерактивное агентство (РИФ+КИБ 2010)
Как выгодно продать интерактивное агентство (РИФ+КИБ 2010)Actis Wunderman
 
Организация social media отдела в крупном агентстве #nastachku
Организация social media отдела в крупном агентстве #nastachkuОрганизация social media отдела в крупном агентстве #nastachku
Организация social media отдела в крупном агентстве #nastachku
Actis Wunderman
 
Nokia Metallica Quest 2010 (кейс)
Nokia Metallica Quest 2010 (кейс)Nokia Metallica Quest 2010 (кейс)
Nokia Metallica Quest 2010 (кейс)Actis Wunderman
 
아이들을 위한 공공지원 사업 계획안
아이들을 위한 공공지원 사업 계획안아이들을 위한 공공지원 사업 계획안
아이들을 위한 공공지원 사업 계획안
종원 윤
 

Viewers also liked (16)

บุคคลสำคัญของบางกอก
บุคคลสำคัญของบางกอกบุคคลสำคัญของบางกอก
บุคคลสำคัญของบางกอก
 
Pinterest Presentation for Small Businesses
Pinterest Presentation for Small BusinessesPinterest Presentation for Small Businesses
Pinterest Presentation for Small Businesses
 
Creative Marketing
Creative MarketingCreative Marketing
Creative Marketing
 
Blog de pol
Blog de polBlog de pol
Blog de pol
 
Blog de pol
Blog de polBlog de pol
Blog de pol
 
A Marketing Fable
A Marketing FableA Marketing Fable
A Marketing Fable
 
บุคคลสำคัญของบางกอก
บุคคลสำคัญของบางกอกบุคคลสำคัญของบางกอก
บุคคลสำคัญของบางกอก
 
Blog de pol
Blog de polBlog de pol
Blog de pol
 
VinaWealth Stock Investing Basics
VinaWealth Stock Investing BasicsVinaWealth Stock Investing Basics
VinaWealth Stock Investing Basics
 
5 Ways to Spring Clean Your Credit Report
5 Ways to Spring Clean Your Credit Report5 Ways to Spring Clean Your Credit Report
5 Ways to Spring Clean Your Credit Report
 
Как выгодно продать интерактивное агентство (РИФ+КИБ 2010)
Как выгодно продать интерактивное агентство (РИФ+КИБ 2010)Как выгодно продать интерактивное агентство (РИФ+КИБ 2010)
Как выгодно продать интерактивное агентство (РИФ+КИБ 2010)
 
Mental health
Mental healthMental health
Mental health
 
Daron malakian
Daron malakianDaron malakian
Daron malakian
 
Организация social media отдела в крупном агентстве #nastachku
Организация social media отдела в крупном агентстве #nastachkuОрганизация social media отдела в крупном агентстве #nastachku
Организация social media отдела в крупном агентстве #nastachku
 
Nokia Metallica Quest 2010 (кейс)
Nokia Metallica Quest 2010 (кейс)Nokia Metallica Quest 2010 (кейс)
Nokia Metallica Quest 2010 (кейс)
 
아이들을 위한 공공지원 사업 계획안
아이들을 위한 공공지원 사업 계획안아이들을 위한 공공지원 사업 계획안
아이들을 위한 공공지원 사업 계획안
 

Similar to Rest in practice

REST and Web API
REST and Web APIREST and Web API
REST and Web API
IT Weekend
 
UserCentric Identity based Service Invocation
UserCentric Identity based Service InvocationUserCentric Identity based Service Invocation
UserCentric Identity based Service Invocation
guestd5dde6
 
About REST. Архитектурные семинары Softengi
About REST. Архитектурные семинары SoftengiAbout REST. Архитектурные семинары Softengi
About REST. Архитектурные семинары Softengi
Softengi
 
RESTful services
RESTful servicesRESTful services
RESTful servicesgouthamrv
 
01. http basics v27
01. http basics v2701. http basics v27
01. http basics v27
Eoin Keary
 
NEPHP '12: Create a RESTful API
NEPHP '12: Create a RESTful APINEPHP '12: Create a RESTful API
NEPHP '12: Create a RESTful APIAndrew Curioso
 
RESTful Web Services with JAX-RS
RESTful Web Services with JAX-RSRESTful Web Services with JAX-RS
RESTful Web Services with JAX-RS
Carol McDonald
 
RESTful SOA - 中科院暑期讲座
RESTful SOA - 中科院暑期讲座RESTful SOA - 中科院暑期讲座
RESTful SOA - 中科院暑期讲座Li Yi
 
Doing REST Right
Doing REST RightDoing REST Right
Doing REST Right
Kerry Buckley
 
Rest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.jsRest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.jsCarol McDonald
 
RESTful Web Services
RESTful Web ServicesRESTful Web Services
RESTful Web Services
Gordon Dickens
 
JavaScript Security: Mastering Cross Domain Communications in complex JS appl...
JavaScript Security: Mastering Cross Domain Communications in complex JS appl...JavaScript Security: Mastering Cross Domain Communications in complex JS appl...
JavaScript Security: Mastering Cross Domain Communications in complex JS appl...
Thomas Witt
 
An introduction to Struts 2 and RESTful applications
An introduction to Struts 2 and RESTful applicationsAn introduction to Struts 2 and RESTful applications
An introduction to Struts 2 and RESTful applications
mrdon
 
Android App Development 06 : Network &amp; Web Services
Android App Development 06 : Network &amp; Web ServicesAndroid App Development 06 : Network &amp; Web Services
Android App Development 06 : Network &amp; Web ServicesAnuchit Chalothorn
 
Ellerslie User Group - ReST Presentation
Ellerslie User Group - ReST PresentationEllerslie User Group - ReST Presentation
Ellerslie User Group - ReST Presentation
Alex Henderson
 
Spring MVC 3 Restful
Spring MVC 3 RestfulSpring MVC 3 Restful
Spring MVC 3 Restful
knight1128
 

Similar to Rest in practice (20)

REST and Web API
REST and Web APIREST and Web API
REST and Web API
 
REST and Web API
REST and Web APIREST and Web API
REST and Web API
 
ASP.NET WEB API
ASP.NET WEB APIASP.NET WEB API
ASP.NET WEB API
 
UserCentric Identity based Service Invocation
UserCentric Identity based Service InvocationUserCentric Identity based Service Invocation
UserCentric Identity based Service Invocation
 
About REST. Архитектурные семинары Softengi
About REST. Архитектурные семинары SoftengiAbout REST. Архитектурные семинары Softengi
About REST. Архитектурные семинары Softengi
 
RESTful services
RESTful servicesRESTful services
RESTful services
 
01. http basics v27
01. http basics v2701. http basics v27
01. http basics v27
 
NEPHP '12: Create a RESTful API
NEPHP '12: Create a RESTful APINEPHP '12: Create a RESTful API
NEPHP '12: Create a RESTful API
 
RESTful Web Services with JAX-RS
RESTful Web Services with JAX-RSRESTful Web Services with JAX-RS
RESTful Web Services with JAX-RS
 
RESTful SOA - 中科院暑期讲座
RESTful SOA - 中科院暑期讲座RESTful SOA - 中科院暑期讲座
RESTful SOA - 中科院暑期讲座
 
Doing REST Right
Doing REST RightDoing REST Right
Doing REST Right
 
Rest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.jsRest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.js
 
Rest
RestRest
Rest
 
RESTful Web Services
RESTful Web ServicesRESTful Web Services
RESTful Web Services
 
Web Scraping with PHP
Web Scraping with PHPWeb Scraping with PHP
Web Scraping with PHP
 
JavaScript Security: Mastering Cross Domain Communications in complex JS appl...
JavaScript Security: Mastering Cross Domain Communications in complex JS appl...JavaScript Security: Mastering Cross Domain Communications in complex JS appl...
JavaScript Security: Mastering Cross Domain Communications in complex JS appl...
 
An introduction to Struts 2 and RESTful applications
An introduction to Struts 2 and RESTful applicationsAn introduction to Struts 2 and RESTful applications
An introduction to Struts 2 and RESTful applications
 
Android App Development 06 : Network &amp; Web Services
Android App Development 06 : Network &amp; Web ServicesAndroid App Development 06 : Network &amp; Web Services
Android App Development 06 : Network &amp; Web Services
 
Ellerslie User Group - ReST Presentation
Ellerslie User Group - ReST PresentationEllerslie User Group - ReST Presentation
Ellerslie User Group - ReST Presentation
 
Spring MVC 3 Restful
Spring MVC 3 RestfulSpring MVC 3 Restful
Spring MVC 3 Restful
 

Recently uploaded

Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 

Recently uploaded (20)

Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 

Rest in practice

  • 1. GET Gábor Török @ EPAM/Szeged
  • 2. Introduction, overview  Best practices  Java support
  • 3.
  • 4. Roy T Fielding, PhD dissertation, 2000  Main characteristics ◦ Client-server ◦ Stateless ◦ Caching ◦ Layered architecture ◦ Code on demand ◦ URIs
  • 5. Richardson’s Maturity Model Image courtesy of Martin Fowler
  • 6. Plain Old XML (over HTTP)  One URI, one method
  • 7. POST /appointmentService HTTP/1.1 <openSlotRequest date="2010-01-04" doctor="mjones"/>
  • 8. Level 0: POX response HTTP/1.1 200 OK <openSlotList> <slot start="1400" end="1450"> <doctor id="mjones"/> </slot> <slot start="1600" end="1650"> <doctor id="mjones"/> </slot> </openSlotList>
  • 9. POST /appointmentService HTTP/1.1 <appointmentRequest> <slot doctor="mjones" start="1400" end="1450"/> <patient id="jsmith"/> </appointmentRequest>
  • 10. Level 0: POX response HTTP/1.1 200 OK <appointment> <slot doctor="mjones" start="1400" end="1450"/> <patient id="jsmith"/> </appointment>
  • 11. Many URIs, one method
  • 13. Level 1: Resources response HTTP/1.1 200 OK <openSlotList> <slot id="1234" doctor="mjones" start="1400" end="1450"/> <slot id="5678" doctor="mjones" start="1600" end="1650"/> </openSlotList>
  • 14. POST /slots/1234 HTTP/1.1 <appointmentRequest> <patient id="jsmith"/> </appointmentRequest>
  • 15. Level 1: Resources response HTTP/1.1 200 OK <appointment id="2468"> <slot id="1234" doctor="mjones" start="1400" end="1450”/> <patient id="jsmith"/> </appointment>
  • 16. Many URIs, many (HTTP) methods  This is what most call REST  Best practices follow
  • 18. Level 2: Verbs response HTTP/1.1 200 OK <openSlotList> <slot id="1234" doctor="mjones" start="1400" end="1450"/> <slot id="5678" doctor="mjones" start="1600" end="1650"/> </openSlotList>
  • 19. POST /slots/1234 HTTP/1.1 <appointmentRequest> <patient id="jsmith"/> </appointmentRequest>
  • 20. Level 2: Verbs response HTTP/1.1 200 OK <appointment id="2468"> <slot id="1234" doctor="mjones" start="1400" end="1450”/> <patient id="jsmith"/> </appointment>
  • 21. W3: „Cool URIs don’t change” vs Roy Fielding: „A REST API must not define fixed resource names or hierarchies”  HATEOAS & self-descriptive messages  Problems: people’s awareness, tools
  • 22. Level 3: Hypermedia response HTTP/1.1 200 OK <openSlotList> <slot id="1234" doctor="mjones” start="1400" end="1450"> <link rel="/linkrels/slot/book" uri="/slots/1234"/> </slot> … </openSlotList>
  • 23. Level 3: Hypermedia response HTTP/1.1 201 Created Location: http://.../slots/1234/appointment <appointment> <slot id="1234" …/> <patient id="jsmith"/> <link rel="/linkrels/appointment/cancel" uri="/slots/1234/appointment"/> <link rel="self" uri="/slots/1234/appointment"/> </appointment>
  • 24. Solves interop problems WSDL contract Strong typing Client- and server bindings Operations (i.e. verbs) WS-* support (Security, GETing/POSTing an XML AtomicTransaction, etc.) Many proxies block PUT Non-intuitive Level 0
  • 25.
  • 26. Resources vs actions getTickets vs /tickets getMusemTickets vs /tickets?type=museum
  • 27. Plural + ID CRUD-style operations Concrete not abstract names Resource GET POST PUT DELETE /tickets List tickets Create a Bulk update Delete all new ticket tickets /tickets/123 Get the Error Update a Delete a details of given ticket given ticket one ticket
  • 28. http://api.company.com/cafe/v1  Major rev only  Numbers, not nicknames, dates, etc.
  • 29. HTTP status codes 200 403 500 503 204 200 400 201 400 500 404 405 401  Short description  Pointer to more information
  • 30. HTTP Status Code: 401 { "status" : "401", "message":"Authenticate", "code": 12345, "more info": http://developers.company.com/docs/er rors/12345 }
  • 31. Ways to differentiate: /tickets/123.json /tickets/123?format=json Accept: application/json  Bonus: application/company.v1+json
  • 32. Pagination: /tickets?offset=50&limit=25  Partial response: /tickets?fields=date,location  Use defaults (documentation!)
  • 33. Session management – REST is stateless  Caching – it’s very much encouraged!  What if nouns are not appropriate – use verbs
  • 34. Security – preferred is OAuth, lot of Basic/Digest over HTTPS in practice  Subdomains: ◦ api ◦ developers for SDK  Clean REST
  • 35.
  • 36. JSR 311: Java API for RESTful Web Services  Annotation-driven @GET, @Path, @PathParam, @Consumes  Implementations Jersey, Restlet, RESTeasy, Apache CXF  Jax-rs-hateoas
  • 38. Spring MVC application essentially  Annotation-driven + XML configuration @RequestMapping et al. + view resolvers, message converters, et al.  spring-hateoas
  • 40. CRUD for JPA-entities using REST semantics  @RestResource  Pagination and sorting support  spring-hateoas
  • 42.
  • 43. Roy Fielding’s dissertation  REST in Practice from O’Reilly  Apigee blog & video tutorials  Articles, forums
  • 44. Levels of REST – REST ≠ CRUD  Consistent view of best practices  Java support
  • 45. Has been in the industry since late ’90s  Has been @EPAM since 2009, acted as a Dev Lead/PM, now Solutions Architect  Has mobile + enterprise background gabor.i.torok@gmail.com

Editor's Notes

  1. Roy Fielding &amp; hisdissertationOne of theprincipalauthorsof HTTP specCo-founder of Apache HTTP server projectWasheavilyinvolvedin HTML and URIsDissertationNo mention of CRUD or POSTLater Fielding saysinhisblogthateven HTTP itself is not a mandatory part of REST (but URI is)HATEOAS is more importantthan CRUD (hypertextdrivesappstatechanges; contentnegotiation)Layeredsystem: gateways, loadbalancers, firewalls, sharedcaches, etc.
  2. Per Roy F: fromlevel 0-2 it’s not REST, 3 IS REST … thetermREST has beenmostlycoupledwithCRUD-likeaccesstodomainobjects0 – URI tunneling:oneURI, one HTTP method POST to a single URI, allattributesasparameter  lookslike SOAP w/o envelope  part of the Web, limited use of availablefeaturesFirewallfriendly (HTTP)Lackssophistication1 – resources … manyURIs, one HTTP method  lots of thought-to-be-RESTfulservices  stilltoocomplex2 – verbs … manyURIs, many HTTP methods  verynice, butstill limited to CRUD scenariosonly3 – hypermedia  resourcesdescribetheirowncapabilities and interconnections  it’s like a HTML pagefromwhereyoucan go vialinks  inadditiontolinks, it’s alsoaboutcontentnegotiation – own (MIME) types, dynamicdiscoveryLevel 1 tackles the question of handling complexity by using divide and conquer, breaking a large service endpoint down into multiple resources.Level 2 introduces a standard set of verbs so that we handle similar situations in the same way, removing unnecessary variation.Level 3 introduces discoverability, providing a way of making a protocol more self-documenting.
  3. Itcan be anythingelsethan XML, really (JSON, YAML, etc)RPC-stylesolutionBasicallylike SOAP
  4. PronounciationHate o’sHateyo’ assHate eeohsExamples:Get the second 50 items from 500, we may get a link back to the first 50 as well as the thirdWe get the resource data along with possible actions we may take upon it  these actions may depend on my authority (authorization)http://www.soatothecloud.com/2012/04/api-gateway-support-for-hateoas-first.html  great JSON example + mention of Gateway APIhttp://timelessrepo.com/haters-gonna-hateoas  good XML example  link tonew comment, commentstoblogentry + toselfproblems that it solves- w3c: coolurisdon’t change  http://www.w3.org/Provider/Style/URI.htmlREST calls return with content in a requested format  these formats have their media types with hints (links) as to what clients can do with the resource  application state may change while „jumping” from one resource to another  self-descriptive messagesREST APIs require the user to know that fixed URL structure (i.e. conventions)  client rewrite is needed when API changesWith SOAP clients figure out what they can do with a given resource from the WSDL  client-side (SOAP) vs server-side (HATEOAS)  fixed vs dynamicproblems that it causesMany applications simply map their backend (DB) object to HTTP (api)  resources != domain objects  resources == domain objects + metadataNew resource definitions might (and should) have their own MIME typesProblemsPeopledon’t understandit’s a problemNo tooling for thisLinkscould be part of theresponseheader  http://blog.steveklabnik.com/posts/2011-08-07-some-people-understand-rest-and-http
  5. Each slot now has a link element which contains a URI to tell us how to book an appointment.
  6. SOAPProtocolvsarchitecturalstyle SOAP has a standard whereas REST doesn’tOperationsvsresources verbsvsnounsRigid (typecheckingin SOAP – sometimesit’s a goodthing), light-weight (REST needs no wrapper, like XML in SOAP)Non-intuitivenessvssimplicity  in REST URL describes almost everything and quiteintuitivetouse &amp; modifySecurity: WS-Securityvs HTTPS/TLS  message-levelvstunnel-levelsecurity  http://blogs.msdn.com/b/vbertocci/archive/2005/04/25/end-to-end-security-or-why-you-shouldn-t-drive-your-motorcycle-naked.aspxWS-AtomicTransaction  ACID transactions over a serviceManyproxiesblock PUT (badto REST)
  7. Safety &amp; Idempotencysafe: no side-effectsIdempotent: can be repeatedinsuccessionwithoutfailureGET is safe and idempotentPUT and DELETE arenotsafe, butidempotentPOST is neithersafenoridempotentAssociationbetweenresources: /owners/123/dogs don’t go deeperthan /resource/identifier/resourceUse ‚?’ for attributes  /dogs?color=blackBe consistent, no mixed plurals&amp;singularsConcretethingslikecoffee, beer NOT drink
  8. api.company.comPut version # asmuchinthe front aspossibleMajor version # onlyDatesas version #s  long, hardtoremember, whichdateformat?Optionalversioning and alwaystakethelatestifomitted
  9. 200 – OK201 – created204 – No content (after DELETE)400 – Badrequest401 – unauthorized403 – Forbidden404 – notfound405 – methodnotallowed500 – internalerror503 – Service unavailablewithRetry-AfterheaderUltimatelythefollowingthreeshould be enough: 200, 400 (pointingourwherevalidationfailed) and 500
  10. JSON wins over otherformats, like XML
  11. PATCH - http://weblog.rubyonrails.org/2012/2/26/edge-rails-patch-is-the-new-primary-http-method-for-updates
  12. Session managementCaching – reducenetworktraffic, loadon servers, latency, hidenetworkfailuresLocal cache + server cacheActions in the absence of resources  use verbs, like /currencyconverter/convert?from=EUR&amp;to=BYR&amp;amount=1000
  13. Thingsremovedfrom here tokeeptime:PATCH - http://weblog.rubyonrails.org/2012/2/26/edge-rails-patch-is-the-new-primary-http-method-for-updates noteveryoneknowswhat HTTP methodsare forParameters/attributes in URL or as part of HTTP header  much easier to develop if in URLSuppress HTTP response codes  usefulwhenourcode is runningin a containerthatintercepts HTTP commslike status codes
  14. Wadl – web applicationdescriptionlanguage (W3.org), wadl2java tool
  15. Spring Data REST (SDR) representsthebottom-upapproach, whereSDRcomesfromthedomainobjectlayer … it’s notreallyRESTful, imo
  16. Has beenintheindustrysince 1998Developer, tester, architect, project managerMobile, enterpriseForum nokiachampion(?), blogger