SlideShare une entreprise Scribd logo
1  sur  22
RESTful Web Services

           20-Jan-2011


        Gordon Dickens
   gordon@gordondickens.com
Who Am I?
   Instructor/Mentor

   Active Tweeter for Open Source Tech Topics
    twitter.com/gdickens

   Certified Instructor for

   DZone Most Valuable Blogger
    dzone.com/page/mvbs – dzone.com/user/284679
    Technophile Blog - technophile.gordondickens.com

   GitZone:github.com/gordonad

   LinkedIn:linkedin.com/in/gordondickens




                                                       2
Web Services
 What are Web Services?
   SOA
   Remote messaging between systems


 SOAP != Web Services
 Web Services != SOAP
 SOAP !opposite of REST
 REST !opposite of SOAP



                                       3
Who is using REST?




                     4
What is REST?
 REpresentationalState Transfer
    term by Roy Fielding
      en.wikipedia.org/wiki/Representational_State_Transfer
      www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm

 Architectural Style
    Design principle
    Not an API
    Not a standard

 Web Services over HTTP
    Client: Browser, Desktop, Mobile Device, etc.
    HTTP supported by most languages & platforms




                                                                         5
Re – S – T
 Representational
   Client requests data AND representation from server
   HTML, PDF, JSON, XLS, etc.

 State
   URIs returned in hypermedia are in context of the current resource
   Available options for the client embedded within
   View state to edit state

 Transfer
   The server transfers hypermedia content to the client

 HATEOAS
   Cool resume building buzzword
   Hypermedia as the Engine of Application State



                                                                         6
REST Benefits
 Representations can be any format
   JSON, XML, PDF, JPG, HTML, etc.
   Client requests standard media type
 Hypermedia
   response contains resource specific links
   provides state transitions
 Cacheable
 HTTP
   Existing Infrastructure
   Language Support


                                                7
REST Introduction
 Take the ROAD back to OOAD
 Nouns are defined in the URI
 Verbs are provided by HTTP
     GET (retrieve)
     POST (create)
     PUT (update)
     DELETE (delete)


 What should the server return from this URI?
   http://myserver:8080/myapp/accounts/234


                                                 8
What’s our Job?
 We must design the URI patterns & flow
 Define URIs with Nouns
 Include identifiers as Path Variables
     GET /accounts/234
     GET /accounts/234/orders
     GET /accounts/234/orders/25

 Parameters provide hints to the server such as
  pagination values or max rows, etc.



                                                   9
URI Design
 For each Resource (noun) define behavior
 Account:
     GET /accounts – returns list of accounts
     GET /accounts/{id} – returns account by id
     POST /accounts – inserts account data
     PUT /accounts/{id} – Updates account by id
     DELETE /accounts/{id} – Close account by id

 Account’s Orders
     GET /accounts/{id}/orders – List all orders for account
     GET /accounts/{id}/orders/{id} – List specific order
     POST /accounts/{id}/orders – Insert order for account
     PUT /accounts/{id}/orders/{id} – Update order
     DELETE /accounts/{id}/orders/{id} – Cancel Order



                                                                10
HTTP Response Codes
 Familiar HTTP Response codes
   200 OK
   404 Page not found
   500 Server is kaput


 RESTful uses standard HTTP codes
     1xx Informational
     2xx Success
     3xx Redirection
     4xx Client Error
     5xx Server Error



                                     11
Designing the flow
 Conditional Headers
   If-Unmodified-Since
   If-Match (etag)
   If-None-Match

   Example of Conditional
    PUT
   Returns:
     200 - OK
     201 - Created
     404 – Not Found
     412 – Precond. Failed
                                 12
Representation Request
 Client to Server
                               HTTP/1.1 200 OK
 GET /accounts/234             Date: …
 HOST: myserver.com
                               Content-Length: 2146
 Accept: application.xml, …
 …
                               <account id=“234”>
                               …
                               </account>


 GET /accounts/234             HTTP/1.1 200 OK
 HOST: myserver.com            Date: …
 Accept: application/json, …   Content-Length: 1027
 …                             {
                               “account”:{“id”:234, …}
                               }


                                                         13
Java & REST
 JAX-RS
   JSR-311
   Jersey (RI), Restlet, CXF, RestEasy



 Spring REST
   leverages formatters & converters
   REST Template – Easy Client development
   Spring Roo – generates RESTfulURIs



                                              14
Spring REST
                                                @RequestMapping
 Annotations for:                              @ResponseStatus
     URL Path                                  @PathVariable
     HTTP Verbs                                @RequestBody
     Request body (payload)                    @ResponseBody
     Response body                             @RequestParam
                                                @RequestHeader
     Header, Parameter & Path variables
     Response Status codes

 Automatic marshalling/unmarshalling of resource
  representations
 <mvc:annotation-driven/>
   Registers automatic formatters, converters &marshallers
   Inspects classpath for Jackson/JSON, JodaTime, etc.


                                                              15
Security - Data
 Same as other messaging approaches


 Encapsulation:
   SSL, TLS, IPsec, etc.


 Encryption:
   PGP, S/MIME, etc.




                                       16
Security - Auth
 Authentication:
      Basic, Digest, X509, etc.
      Spring Security

    Client Sends
   GET /account/123

      Server Responds with:
   HTTP/1.1 401 Unauthorized
   WWW-Authenticate: Basic realm=”MyApp Realm”



 Authorization
      Standard web.xml security configuration
      Spring Security
      OAuth




                                                 17
“An open protocol to allow secure API authorization in a
    simple and standard method from desktop to web
                      applications.”

                    http://oauth.net



              code.google.com/p/oauth/

                                                       18
OAuth Participants
 Client
   Our app
 Server
   Who we want to connecting with
 Service Provider
   Service that authenticates credentials




                                             19
OAuth Safety Dance




                     20
“OpenID is a decentralized authentication protocol that makes it
         easy for people to sign up and access web accounts.”

                                 openid.net
                   openid.net/developers/libraries/#java




 OpenID 2.0 Java 5 impl for                 Java REST framework,
  Google Federated Login                        openid 2.0, OAuth consumer
                                                & service provider, JSON
   code.google.com/p/jopenid/                   IOC
                                               code.google.com/p/dyuproject/



                                                                          21
Questions?
Email: gordon@gordondickens.com

Twitter: twitter.com/gdickens

Blog: technophile.gordondickens.com

Git: github.com/gordonad

LinkedIn: linkedin.com/in/gordondickens




                                          22

Contenu connexe

Tendances

The glory of REST in Java: Spring HATEOAS, RAML, Temenos IRIS
The glory of REST in Java: Spring HATEOAS, RAML, Temenos IRISThe glory of REST in Java: Spring HATEOAS, RAML, Temenos IRIS
The glory of REST in Java: Spring HATEOAS, RAML, Temenos IRISGeert Pante
 
Dave Carroll Application Services Salesforce
Dave Carroll Application Services SalesforceDave Carroll Application Services Salesforce
Dave Carroll Application Services Salesforcedeimos
 
SharePoint Data Anywhere and Everywhere by Chris Beckett - SPTechCon
SharePoint Data Anywhere and Everywhere by Chris Beckett - SPTechConSharePoint Data Anywhere and Everywhere by Chris Beckett - SPTechCon
SharePoint Data Anywhere and Everywhere by Chris Beckett - SPTechConSPTechCon
 
Web development with ASP.NET Web API
Web development with ASP.NET Web APIWeb development with ASP.NET Web API
Web development with ASP.NET Web APIDamir Dobric
 
Web Center Services and Framework
Web Center Services and  FrameworkWeb Center Services and  Framework
Web Center Services and FrameworkJaime Cid
 
Making Sense of API Access Control
Making Sense of API Access ControlMaking Sense of API Access Control
Making Sense of API Access ControlCA API Management
 
REST Architecture with use case and example
REST Architecture with use case and exampleREST Architecture with use case and example
REST Architecture with use case and exampleShailesh singh
 
Together Cheerfully to Walk with Hypermedia
Together Cheerfully to Walk with HypermediaTogether Cheerfully to Walk with Hypermedia
Together Cheerfully to Walk with HypermediaVladimir Tsukur
 
Server-Side Programming Primer
Server-Side Programming PrimerServer-Side Programming Primer
Server-Side Programming PrimerIvano Malavolta
 
24032022 Zero Trust for Developers Pub.pdf
24032022 Zero Trust for Developers Pub.pdf24032022 Zero Trust for Developers Pub.pdf
24032022 Zero Trust for Developers Pub.pdfTomasz Kopacz
 
Vaadin - Rich Web Applications in Server-side Java without Plug-ins or JavaSc...
Vaadin - Rich Web Applications in Server-side Java without Plug-ins or JavaSc...Vaadin - Rich Web Applications in Server-side Java without Plug-ins or JavaSc...
Vaadin - Rich Web Applications in Server-side Java without Plug-ins or JavaSc...Joonas Lehtinen
 
Jsf login logout project
Jsf login logout projectJsf login logout project
Jsf login logout projectGagandeep Singh
 
Java Web Programming [1/9] : Introduction to Web Application
Java Web Programming [1/9] : Introduction to Web ApplicationJava Web Programming [1/9] : Introduction to Web Application
Java Web Programming [1/9] : Introduction to Web ApplicationIMC Institute
 
Java power to the SOA developer (ODTUG Kaleidoscope 2010)
Java power to the SOA developer (ODTUG Kaleidoscope 2010)Java power to the SOA developer (ODTUG Kaleidoscope 2010)
Java power to the SOA developer (ODTUG Kaleidoscope 2010)Lucas Jellema
 

Tendances (20)

The glory of REST in Java: Spring HATEOAS, RAML, Temenos IRIS
The glory of REST in Java: Spring HATEOAS, RAML, Temenos IRISThe glory of REST in Java: Spring HATEOAS, RAML, Temenos IRIS
The glory of REST in Java: Spring HATEOAS, RAML, Temenos IRIS
 
Dave Carroll Application Services Salesforce
Dave Carroll Application Services SalesforceDave Carroll Application Services Salesforce
Dave Carroll Application Services Salesforce
 
SharePoint Data Anywhere and Everywhere by Chris Beckett - SPTechCon
SharePoint Data Anywhere and Everywhere by Chris Beckett - SPTechConSharePoint Data Anywhere and Everywhere by Chris Beckett - SPTechCon
SharePoint Data Anywhere and Everywhere by Chris Beckett - SPTechCon
 
Web development with ASP.NET Web API
Web development with ASP.NET Web APIWeb development with ASP.NET Web API
Web development with ASP.NET Web API
 
Web Center Services and Framework
Web Center Services and  FrameworkWeb Center Services and  Framework
Web Center Services and Framework
 
Making Sense of API Access Control
Making Sense of API Access ControlMaking Sense of API Access Control
Making Sense of API Access Control
 
Mashups
MashupsMashups
Mashups
 
API Design- Best Practices
API Design-   Best PracticesAPI Design-   Best Practices
API Design- Best Practices
 
REST Architecture with use case and example
REST Architecture with use case and exampleREST Architecture with use case and example
REST Architecture with use case and example
 
Together Cheerfully to Walk with Hypermedia
Together Cheerfully to Walk with HypermediaTogether Cheerfully to Walk with Hypermedia
Together Cheerfully to Walk with Hypermedia
 
Take a REST!
Take a REST!Take a REST!
Take a REST!
 
Server-Side Programming Primer
Server-Side Programming PrimerServer-Side Programming Primer
Server-Side Programming Primer
 
An Introduction To REST API
An Introduction To REST APIAn Introduction To REST API
An Introduction To REST API
 
24032022 Zero Trust for Developers Pub.pdf
24032022 Zero Trust for Developers Pub.pdf24032022 Zero Trust for Developers Pub.pdf
24032022 Zero Trust for Developers Pub.pdf
 
Introduction To REST
Introduction To RESTIntroduction To REST
Introduction To REST
 
Vaadin - Rich Web Applications in Server-side Java without Plug-ins or JavaSc...
Vaadin - Rich Web Applications in Server-side Java without Plug-ins or JavaSc...Vaadin - Rich Web Applications in Server-side Java without Plug-ins or JavaSc...
Vaadin - Rich Web Applications in Server-side Java without Plug-ins or JavaSc...
 
Hypermedia APIs
Hypermedia APIsHypermedia APIs
Hypermedia APIs
 
Jsf login logout project
Jsf login logout projectJsf login logout project
Jsf login logout project
 
Java Web Programming [1/9] : Introduction to Web Application
Java Web Programming [1/9] : Introduction to Web ApplicationJava Web Programming [1/9] : Introduction to Web Application
Java Web Programming [1/9] : Introduction to Web Application
 
Java power to the SOA developer (ODTUG Kaleidoscope 2010)
Java power to the SOA developer (ODTUG Kaleidoscope 2010)Java power to the SOA developer (ODTUG Kaleidoscope 2010)
Java power to the SOA developer (ODTUG Kaleidoscope 2010)
 

En vedette

Intro to OSGi and Eclipse Virgo
Intro to OSGi and Eclipse VirgoIntro to OSGi and Eclipse Virgo
Intro to OSGi and Eclipse VirgoGordon Dickens
 
Eclipse e4 Tutorial - EclipseCon 2010
Eclipse e4 Tutorial - EclipseCon 2010Eclipse e4 Tutorial - EclipseCon 2010
Eclipse e4 Tutorial - EclipseCon 2010Lars Vogel
 
Eclipse Plug-in Develompent Tips And Tricks
Eclipse Plug-in Develompent Tips And TricksEclipse Plug-in Develompent Tips And Tricks
Eclipse Plug-in Develompent Tips And TricksChris Aniszczyk
 
Eclipse Extensions Vs OSGI Services Tikal@ EclipseDemoCamps Tel Aviv
Eclipse Extensions Vs OSGI Services   Tikal@ EclipseDemoCamps Tel AvivEclipse Extensions Vs OSGI Services   Tikal@ EclipseDemoCamps Tel Aviv
Eclipse Extensions Vs OSGI Services Tikal@ EclipseDemoCamps Tel Avivguestb69b980e
 
OSGi Technology, Eclipse and Convergence - Jeff McAffer, IBM
OSGi Technology, Eclipse and Convergence - Jeff McAffer, IBMOSGi Technology, Eclipse and Convergence - Jeff McAffer, IBM
OSGi Technology, Eclipse and Convergence - Jeff McAffer, IBMmfrancis
 
OSGi, Eclipse and API Tooling
OSGi, Eclipse and API ToolingOSGi, Eclipse and API Tooling
OSGi, Eclipse and API ToolingChris Aniszczyk
 
Eclipse plug in development
Eclipse plug in developmentEclipse plug in development
Eclipse plug in developmentMartin Toshev
 
Visual Design with Data
Visual Design with DataVisual Design with Data
Visual Design with DataSeth Familian
 

En vedette (8)

Intro to OSGi and Eclipse Virgo
Intro to OSGi and Eclipse VirgoIntro to OSGi and Eclipse Virgo
Intro to OSGi and Eclipse Virgo
 
Eclipse e4 Tutorial - EclipseCon 2010
Eclipse e4 Tutorial - EclipseCon 2010Eclipse e4 Tutorial - EclipseCon 2010
Eclipse e4 Tutorial - EclipseCon 2010
 
Eclipse Plug-in Develompent Tips And Tricks
Eclipse Plug-in Develompent Tips And TricksEclipse Plug-in Develompent Tips And Tricks
Eclipse Plug-in Develompent Tips And Tricks
 
Eclipse Extensions Vs OSGI Services Tikal@ EclipseDemoCamps Tel Aviv
Eclipse Extensions Vs OSGI Services   Tikal@ EclipseDemoCamps Tel AvivEclipse Extensions Vs OSGI Services   Tikal@ EclipseDemoCamps Tel Aviv
Eclipse Extensions Vs OSGI Services Tikal@ EclipseDemoCamps Tel Aviv
 
OSGi Technology, Eclipse and Convergence - Jeff McAffer, IBM
OSGi Technology, Eclipse and Convergence - Jeff McAffer, IBMOSGi Technology, Eclipse and Convergence - Jeff McAffer, IBM
OSGi Technology, Eclipse and Convergence - Jeff McAffer, IBM
 
OSGi, Eclipse and API Tooling
OSGi, Eclipse and API ToolingOSGi, Eclipse and API Tooling
OSGi, Eclipse and API Tooling
 
Eclipse plug in development
Eclipse plug in developmentEclipse plug in development
Eclipse plug in development
 
Visual Design with Data
Visual Design with DataVisual Design with Data
Visual Design with Data
 

Similaire à RESTful Web Services

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 services
RESTful servicesRESTful services
RESTful servicesgouthamrv
 
Best Practices for Architecting a Pragmatic Web API.
Best Practices for Architecting a Pragmatic Web API.Best Practices for Architecting a Pragmatic Web API.
Best Practices for Architecting a Pragmatic Web API.Mario Cardinal
 
REST APIs in the context of single-page applications
REST APIs in the context of single-page applicationsREST APIs in the context of single-page applications
REST APIs in the context of single-page applicationsyoranbe
 
Rest presentation
Rest  presentationRest  presentation
Rest presentationsrividhyau
 
Pinterest like site using REST and Bottle
Pinterest like site using REST and Bottle Pinterest like site using REST and Bottle
Pinterest like site using REST and Bottle Gaurav Bhardwaj
 
RefCard RESTful API Design
RefCard RESTful API DesignRefCard RESTful API Design
RefCard RESTful API DesignOCTO Technology
 
JAX-RS JavaOne Hyderabad, India 2011
JAX-RS JavaOne Hyderabad, India 2011JAX-RS JavaOne Hyderabad, India 2011
JAX-RS JavaOne Hyderabad, India 2011Shreedhar Ganapathy
 
REST and Web API
REST and Web APIREST and Web API
REST and Web APIIT Weekend
 
RESTful SOA - 中科院暑期讲座
RESTful SOA - 中科院暑期讲座RESTful SOA - 中科院暑期讲座
RESTful SOA - 中科院暑期讲座Li Yi
 
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
 
How APIs Can Be Secured in Mobile Environments
How APIs Can Be Secured in Mobile EnvironmentsHow APIs Can Be Secured in Mobile Environments
How APIs Can Be Secured in Mobile EnvironmentsWSO2
 
Service approach for development Rest API in Symfony2
Service approach for development Rest API in Symfony2Service approach for development Rest API in Symfony2
Service approach for development Rest API in Symfony2Sumy PHP User Grpoup
 
Time to REST: testing web services
Time to REST: testing web servicesTime to REST: testing web services
Time to REST: testing web servicesIurii Kutelmakh
 

Similaire à RESTful Web Services (20)

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 services
RESTful servicesRESTful services
RESTful services
 
Best Practices for Architecting a Pragmatic Web API.
Best Practices for Architecting a Pragmatic Web API.Best Practices for Architecting a Pragmatic Web API.
Best Practices for Architecting a Pragmatic Web API.
 
REST APIs in the context of single-page applications
REST APIs in the context of single-page applicationsREST APIs in the context of single-page applications
REST APIs in the context of single-page applications
 
Rest presentation
Rest  presentationRest  presentation
Rest presentation
 
Pinterest like site using REST and Bottle
Pinterest like site using REST and Bottle Pinterest like site using REST and Bottle
Pinterest like site using REST and Bottle
 
RefCard RESTful API Design
RefCard RESTful API DesignRefCard RESTful API Design
RefCard RESTful API Design
 
JAX-RS JavaOne Hyderabad, India 2011
JAX-RS JavaOne Hyderabad, India 2011JAX-RS JavaOne Hyderabad, India 2011
JAX-RS JavaOne Hyderabad, India 2011
 
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
 
Rest Webservice
Rest WebserviceRest Webservice
Rest Webservice
 
RESTful SOA - 中科院暑期讲座
RESTful SOA - 中科院暑期讲座RESTful SOA - 中科院暑期讲座
RESTful SOA - 中科院暑期讲座
 
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
 
Getting Started with API Management
Getting Started with API ManagementGetting Started with API Management
Getting Started with API Management
 
How APIs Can Be Secured in Mobile Environments
How APIs Can Be Secured in Mobile EnvironmentsHow APIs Can Be Secured in Mobile Environments
How APIs Can Be Secured in Mobile Environments
 
Service approach for development Rest API in Symfony2
Service approach for development Rest API in Symfony2Service approach for development Rest API in Symfony2
Service approach for development Rest API in Symfony2
 
Time to REST: testing web services
Time to REST: testing web servicesTime to REST: testing web services
Time to REST: testing web services
 
Restful design at work v2.0
Restful design at work v2.0Restful design at work v2.0
Restful design at work v2.0
 
WebApp #3 : API
WebApp #3 : APIWebApp #3 : API
WebApp #3 : API
 

Dernier

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 FMESafe Software
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024SynarionITSolutions
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 

Dernier (20)

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
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 

RESTful Web Services

  • 1. RESTful Web Services 20-Jan-2011 Gordon Dickens gordon@gordondickens.com
  • 2. Who Am I?  Instructor/Mentor  Active Tweeter for Open Source Tech Topics twitter.com/gdickens  Certified Instructor for  DZone Most Valuable Blogger dzone.com/page/mvbs – dzone.com/user/284679 Technophile Blog - technophile.gordondickens.com  GitZone:github.com/gordonad  LinkedIn:linkedin.com/in/gordondickens 2
  • 3. Web Services  What are Web Services?  SOA  Remote messaging between systems  SOAP != Web Services  Web Services != SOAP  SOAP !opposite of REST  REST !opposite of SOAP 3
  • 4. Who is using REST? 4
  • 5. What is REST?  REpresentationalState Transfer  term by Roy Fielding  en.wikipedia.org/wiki/Representational_State_Transfer  www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm  Architectural Style  Design principle  Not an API  Not a standard  Web Services over HTTP  Client: Browser, Desktop, Mobile Device, etc.  HTTP supported by most languages & platforms 5
  • 6. Re – S – T  Representational  Client requests data AND representation from server  HTML, PDF, JSON, XLS, etc.  State  URIs returned in hypermedia are in context of the current resource  Available options for the client embedded within  View state to edit state  Transfer  The server transfers hypermedia content to the client  HATEOAS  Cool resume building buzzword  Hypermedia as the Engine of Application State 6
  • 7. REST Benefits  Representations can be any format  JSON, XML, PDF, JPG, HTML, etc.  Client requests standard media type  Hypermedia  response contains resource specific links  provides state transitions  Cacheable  HTTP  Existing Infrastructure  Language Support 7
  • 8. REST Introduction  Take the ROAD back to OOAD  Nouns are defined in the URI  Verbs are provided by HTTP  GET (retrieve)  POST (create)  PUT (update)  DELETE (delete)  What should the server return from this URI?  http://myserver:8080/myapp/accounts/234 8
  • 9. What’s our Job?  We must design the URI patterns & flow  Define URIs with Nouns  Include identifiers as Path Variables  GET /accounts/234  GET /accounts/234/orders  GET /accounts/234/orders/25  Parameters provide hints to the server such as pagination values or max rows, etc. 9
  • 10. URI Design  For each Resource (noun) define behavior  Account:  GET /accounts – returns list of accounts  GET /accounts/{id} – returns account by id  POST /accounts – inserts account data  PUT /accounts/{id} – Updates account by id  DELETE /accounts/{id} – Close account by id  Account’s Orders  GET /accounts/{id}/orders – List all orders for account  GET /accounts/{id}/orders/{id} – List specific order  POST /accounts/{id}/orders – Insert order for account  PUT /accounts/{id}/orders/{id} – Update order  DELETE /accounts/{id}/orders/{id} – Cancel Order 10
  • 11. HTTP Response Codes  Familiar HTTP Response codes  200 OK  404 Page not found  500 Server is kaput  RESTful uses standard HTTP codes  1xx Informational  2xx Success  3xx Redirection  4xx Client Error  5xx Server Error 11
  • 12. Designing the flow  Conditional Headers  If-Unmodified-Since  If-Match (etag)  If-None-Match  Example of Conditional PUT  Returns:  200 - OK  201 - Created  404 – Not Found  412 – Precond. Failed 12
  • 13. Representation Request  Client to Server HTTP/1.1 200 OK GET /accounts/234 Date: … HOST: myserver.com Content-Length: 2146 Accept: application.xml, … … <account id=“234”> … </account> GET /accounts/234 HTTP/1.1 200 OK HOST: myserver.com Date: … Accept: application/json, … Content-Length: 1027 … { “account”:{“id”:234, …} } 13
  • 14. Java & REST  JAX-RS  JSR-311  Jersey (RI), Restlet, CXF, RestEasy  Spring REST  leverages formatters & converters  REST Template – Easy Client development  Spring Roo – generates RESTfulURIs 14
  • 15. Spring REST @RequestMapping  Annotations for: @ResponseStatus  URL Path @PathVariable  HTTP Verbs @RequestBody  Request body (payload) @ResponseBody  Response body @RequestParam @RequestHeader  Header, Parameter & Path variables  Response Status codes  Automatic marshalling/unmarshalling of resource representations  <mvc:annotation-driven/>  Registers automatic formatters, converters &marshallers  Inspects classpath for Jackson/JSON, JodaTime, etc. 15
  • 16. Security - Data  Same as other messaging approaches  Encapsulation:  SSL, TLS, IPsec, etc.  Encryption:  PGP, S/MIME, etc. 16
  • 17. Security - Auth  Authentication:  Basic, Digest, X509, etc.  Spring Security  Client Sends GET /account/123  Server Responds with: HTTP/1.1 401 Unauthorized WWW-Authenticate: Basic realm=”MyApp Realm”  Authorization  Standard web.xml security configuration  Spring Security  OAuth 17
  • 18. “An open protocol to allow secure API authorization in a simple and standard method from desktop to web applications.” http://oauth.net code.google.com/p/oauth/ 18
  • 19. OAuth Participants  Client  Our app  Server  Who we want to connecting with  Service Provider  Service that authenticates credentials 19
  • 21. “OpenID is a decentralized authentication protocol that makes it easy for people to sign up and access web accounts.” openid.net openid.net/developers/libraries/#java  OpenID 2.0 Java 5 impl for  Java REST framework, Google Federated Login openid 2.0, OAuth consumer & service provider, JSON code.google.com/p/jopenid/ IOC code.google.com/p/dyuproject/ 21
  • 22. Questions? Email: gordon@gordondickens.com Twitter: twitter.com/gdickens Blog: technophile.gordondickens.com Git: github.com/gordonad LinkedIn: linkedin.com/in/gordondickens 22