SlideShare ist ein Scribd-Unternehmen logo
1 von 24
Web Services (NSWI145)
Lecture 07: RESTful Web Services

  Martin Nečaský, Ph.D.
  Faculty of Mathematics and Physics
  Charles University in Prague, Czech Republic
What is REST?
   REpresentation State Transfer
   software architectural style for building
    distributed hypermedia systems
   set of following architectural principles
       resource orientation
       unique resource identification
       stateless client/server interaction
       uniform interface
   e.g. Web architecture is based on the same
    principles as REST
       but REST principles were derived from the
        architecture of Web (Roy Fielding dissertation)
Principle 1: Resource Orientation
   resource = concrete or even abstract thing/action
    we want to publish
     everything is resource in REST
   each resource has its representation = document
    that can be sent between communicating peers
     representation format needs to be established
       • different (meta-)formats may be used (e.g. HTML, XML,
         JSON, RDF, AtomPub, ...)
       • each resource can have more representations (in different
         formats)
     representation contains links to related resources
       • representation format must support links
       • applications which consume resources navigate instead of
         calling
Principle 2: Unique Resource Identification
   each resource has unique ID (name)
     universal syntax for resource IDs is necessary, e.g. URI
     ID serves not just as a name but also as a means of
      accessing resource representation
     parametrized IDs
        http://www.company.org/customer?name=John

   distinguish resource ID from resource representation ID
    (e.g. HTML, XML, JSON, RDF documents)
     if resource = document then resource ID = resource
      representation ID
     otherwise we need strategy to allow clients to request
      specific resource representation
Principle 2: Unique Resource Identification
   direct dereferencing
     resource ID is not dereferenceable
     client has to know particular resource
      representation IDs
   e.g. Twitter uses direct dereferencing
https://api.twitter.com/1/statuses/user_timeline.json
https://api.twitter.com/1/statuses/user_timeline.xml
Principle 2: Unique Resource Identification
   303 URIs
     resource ID is dereferenceable
     HTTP mechanism
     two requests
       • client requests resource ID and specified preferred
         resource representation format
          – server sends resource representation ID
       • client requests resource representation ID
Principle 2: Unique Resource Identification


                                                         Server
                   GET /customer?name=John
                   Host: www.company.org
client             Accept: text/xml




                                                         Server
         HTTP/1.1 303 See Other
         Location:
client   http://www.company.org/customer.xml?name=John




                                                         Server
                 GET /customer.xml?name=John
                 Host: www.company.org
client           Accept: text/xml
Principle 2: Unique Resource Identification
   how to set-up 303 URIs?
   e.g. Apache HTTPD (.htaccess file)
RewriteCond %{HTTP_ACCEPT} application/rdf+xml
RewriteRule ^customer customer.rdf [R=303]




http://www.company.org/            http://www.company.org/
   customer?name=John               customer.xml?name=John
Principle 2: Unique Resource Identification
   avoid parametrized resource ID
     e.g.
             http://www.company.org/customer/John
     instead of
        http://www.company.org/customer?name=John




RewriteCond %{HTTP_ACCEPT} application/rdf+xml
RewriteRule ^customer/([a-zA-Z]+)$ customer.rdf?name=John
Principle 3: Stateless Client/Server
                 Communication
   request/response message exchange
   separation of concerns principle
     clients separated from servers by interface
     clients are not concerned with data storage and
      (most) application logic
     servers are not concerned with user interface or
      state (server simplicity and scalability)
     independent evolution of clients and server
     e.g. HTTP request/response, SOAP
      request/response message exchange pattern, etc.
Principle 3: Stateless Client/Server
                  Communication
   stateless communication
     no state in server-side applications
     move state to clients and/or resources
   resource state is the same for every client
     client changes to resource state affect all other
      clients
   client state is specific for each particular client
     communication state
Principle 4: Resource Manipulation
   uniform interface for resource manipulation
     small set of operations which apply for everything
       • e.g. CRUD operations (Create, Retrieve, Update, Delete)
     small set of verbs which apply to large set of
      nouns
       • if many applications need new verb, uniform interface
         can be extended
   do not encode verbs into resource identifiers
        http://www.company.org/addCustomer?name=John
Principle 4: Resource Manipulation
   when HTTP protocol is used, following four operations are
    usually considered
     GET = requests representation of the specified resource
        • read-only operation, should be safe = should not cause any side-
          effects
     PUT = uploads representation of the specified resource
        • write operation, should be idempotent
            – idempotent = may cause side effects but its multiple calls cause the same
              effect
            – being idempotent means being simple = identical request causes the same
              state change independently of how many times it has been called
     DELETE = deletes the specified resource
        • write operation, should be idempotent
     POST = submits data to be processed to the specified resource
        • it can update the resource
        • generally not safe and not idempotent
RESTful Web Services
   RESTful Web Service
     enables manipulation with set of resources
     typically uses XML, JSON or RDF for resource
      representation
     uses URLs as resource identifiers
     stateless
     HTTP methods GET/PUT/DELETE/POST for
      resource manipulation
   like Web application but for machines instead
    of humans
RESTful Web Services
Operation       Resource representing                   Resource representing
                collection of individuals               individual
GET             List members in collection              Retrieve individual
                •   e.g. weekly list public contracts   •   e.g. retrieve public contract
PUT             Update collection with                  Update individual
                another one                             •   e.g. update public contract
                •   e.g. replace weekly list of             representation with new
                    public contracts at the                 representation
                    beginning of new week
DELETE          Delete entire collection                Delete individual
                •   e.g. delete weekly list of          •   e.g. delete public contract
                    public contracts
POST            Create member of                        Create part of individual
                collection with auto-ID                 •   e.g. create public contract
                •   e.g. add new public contract to         tender
                    the collection and generate its
                    ID
JAX-RS (Jersey Impl.) with Tomcat + Eclipse
   download Jersey
      https://jersey.dev.java.net/
      (A zip of Jersey containing the Jersey jars, core dependencies (it does not provide
       dependencies for third party jars beyond those for JSON support) and JavaDoc)
   create new Eclipse Dynamic Web Project
    ProjectName
      Apache Tomcat as Target runtime
   ProjectName project > Properties
      Java Build Path > Libraries > Add External JARs...
          • add JARs from Jersey zip
   copy JARs from Jersey zip to WEB-INF/lib
   modify WEB-INF/web.xml
JAX-RS (Jersey Impl.) with Tomcat + Eclipse

   class PublicContracts01 in
    Procurement_REST_WS project
      http://localhost:8080/Procurement_REST_WS/res
       ources/PublicContracts01/
      provides simple representation of “List of public
       contracts” resource in plain text, HTML and XML
      basic JAX-RS annotations
        • @Path
        • @GET
        • @Produces
JAX-RS (Jersey Impl.) with Tomcat + Eclipse

   test with cURL (curl_PublicContracts01.bat)
      http://curl.haxx.se/download.html
JAX-RS (Jersey Impl.) with Tomcat + Eclipse
   class PublicContracts02 in Procurement_REST_WS project
      http://localhost:8080/Procurement_REST_WS/resources/Public
       Contracts02/
      getPublicContract method which returns XML or JSON
       representation of public contract to GET request
        • class PublicContract
        • JAXB annotation (provides XML and JSON binding)
            – @XmlRootElement
      listContracts method returns XML or JSON representation of all
       public contracts in collection to GET request
      listContractsHTML method returns HTML representation of all
       public contracts in collection to GET request
      JAX-RS annotations
        • @Path – path with path parameter
        • @PathParam – association of path parameter with method parameter
JAX-RS (Jersey Impl.) with Tomcat + Eclipse

   test
      http://localhost:8080/Procurement_REST_WS/res
       ources/PublicContracts02/
      http://localhost:8080/Procurement_REST_WS/res
       ources/PublicContracts02/4
JAX-RS (Jersey Impl.) with Tomcat + Eclipse
   class PublicContracts03 in
    Procurement_REST_WS project
      http://localhost:8080/Procurement_REST_WS/res
       ources/PublicContracts03/
      putPublicContract updates existing or creates new
       public contract
      deletePublicContract deletes existing public
       contract
      JAX-RS annotations
        • @PUT
        • @DELETE
JAX-RS (Jersey Impl.) with Tomcat + Eclipse

   test with cURL (curl_PublicContracts03.bat)
JAX-RS (Jersey Impl.) with Tomcat + Eclipse

   class PublicContracts04 in
    Procurement_REST_WS project
      http://localhost:8080/Procurement_REST_WS/res
       ources/PublicContracts04/
      createPublicContract creates new contract on
       POST request
      JAX-RS annotations
       • @POST
JAX-RS (Jersey Impl.) with Tomcat + Eclipse

   test with form_PublicContracts04.html

Weitere ähnliche Inhalte

Was ist angesagt?

RestFull Webservices with JAX-RS
RestFull Webservices with JAX-RSRestFull Webservices with JAX-RS
RestFull Webservices with JAX-RSNeil Ghosh
 
RESTful Web Services with JAX-RS
RESTful Web Services with JAX-RSRESTful Web Services with JAX-RS
RESTful Web Services with JAX-RSCarol McDonald
 
Json to hive_schema_generator
Json to hive_schema_generatorJson to hive_schema_generator
Json to hive_schema_generatorPayal Jain
 
Things I wish web graduates knew
Things I wish web graduates knewThings I wish web graduates knew
Things I wish web graduates knewLorna Mitchell
 
Introduction to RESTful Webservices in JAVA
Introduction to RESTful Webservices  in JAVA Introduction to RESTful Webservices  in JAVA
Introduction to RESTful Webservices in JAVA psrpatnaik
 
Novelties in Java EE 7: JAX-RS 2.0 + IPT REST HATEOAS Polling Demo @ BGOUG Co...
Novelties in Java EE 7: JAX-RS 2.0 + IPT REST HATEOAS Polling Demo @ BGOUG Co...Novelties in Java EE 7: JAX-RS 2.0 + IPT REST HATEOAS Polling Demo @ BGOUG Co...
Novelties in Java EE 7: JAX-RS 2.0 + IPT REST HATEOAS Polling Demo @ BGOUG Co...Trayan Iliev
 
A Conversation About REST
A Conversation About RESTA Conversation About REST
A Conversation About RESTMike Wilcox
 
Webservice for android ppt
Webservice for android pptWebservice for android ppt
Webservice for android pptsantosh lamba
 
Consuming RESTful services in PHP
Consuming RESTful services in PHPConsuming RESTful services in PHP
Consuming RESTful services in PHPZoran Jeremic
 
Virtuoso Sponger - RDFizer Middleware for creating RDF from non RDF Data Sources
Virtuoso Sponger - RDFizer Middleware for creating RDF from non RDF Data SourcesVirtuoso Sponger - RDFizer Middleware for creating RDF from non RDF Data Sources
Virtuoso Sponger - RDFizer Middleware for creating RDF from non RDF Data Sourcesrumito
 
A Conversation About REST - Extended Version
A Conversation About REST - Extended VersionA Conversation About REST - Extended Version
A Conversation About REST - Extended VersionJeremy Brown
 
Xcap tutorial
Xcap tutorialXcap tutorial
Xcap tutorialwanglixue
 

Was ist angesagt? (20)

RestFull Webservices with JAX-RS
RestFull Webservices with JAX-RSRestFull Webservices with JAX-RS
RestFull Webservices with JAX-RS
 
RESTful Web Services with JAX-RS
RESTful Web Services with JAX-RSRESTful Web Services with JAX-RS
RESTful Web Services with JAX-RS
 
Json to hive_schema_generator
Json to hive_schema_generatorJson to hive_schema_generator
Json to hive_schema_generator
 
Intoduction to php web services and json
Intoduction to php  web services and jsonIntoduction to php  web services and json
Intoduction to php web services and json
 
Things I wish web graduates knew
Things I wish web graduates knewThings I wish web graduates knew
Things I wish web graduates knew
 
Introduction to RESTful Webservices in JAVA
Introduction to RESTful Webservices  in JAVA Introduction to RESTful Webservices  in JAVA
Introduction to RESTful Webservices in JAVA
 
Novelties in Java EE 7: JAX-RS 2.0 + IPT REST HATEOAS Polling Demo @ BGOUG Co...
Novelties in Java EE 7: JAX-RS 2.0 + IPT REST HATEOAS Polling Demo @ BGOUG Co...Novelties in Java EE 7: JAX-RS 2.0 + IPT REST HATEOAS Polling Demo @ BGOUG Co...
Novelties in Java EE 7: JAX-RS 2.0 + IPT REST HATEOAS Polling Demo @ BGOUG Co...
 
OAuth: Trust Issues
OAuth: Trust IssuesOAuth: Trust Issues
OAuth: Trust Issues
 
A Conversation About REST
A Conversation About RESTA Conversation About REST
A Conversation About REST
 
Xcap
XcapXcap
Xcap
 
Webservice for android ppt
Webservice for android pptWebservice for android ppt
Webservice for android ppt
 
Consuming RESTful services in PHP
Consuming RESTful services in PHPConsuming RESTful services in PHP
Consuming RESTful services in PHP
 
xcap
xcapxcap
xcap
 
Servlet basics
Servlet basicsServlet basics
Servlet basics
 
Virtuoso Sponger - RDFizer Middleware for creating RDF from non RDF Data Sources
Virtuoso Sponger - RDFizer Middleware for creating RDF from non RDF Data SourcesVirtuoso Sponger - RDFizer Middleware for creating RDF from non RDF Data Sources
Virtuoso Sponger - RDFizer Middleware for creating RDF from non RDF Data Sources
 
RESTEasy
RESTEasyRESTEasy
RESTEasy
 
DataBearings: A semantic platform for data integration on IoT, Artem Katasonov
DataBearings: A semantic platform for data integration on IoT, Artem KatasonovDataBearings: A semantic platform for data integration on IoT, Artem Katasonov
DataBearings: A semantic platform for data integration on IoT, Artem Katasonov
 
A Conversation About REST - Extended Version
A Conversation About REST - Extended VersionA Conversation About REST - Extended Version
A Conversation About REST - Extended Version
 
Introduction to JAX-RS
Introduction to JAX-RSIntroduction to JAX-RS
Introduction to JAX-RS
 
Xcap tutorial
Xcap tutorialXcap tutorial
Xcap tutorial
 

Andere mochten auch

Web Services - Business Process Execution Language
Web Services - Business Process Execution LanguageWeb Services - Business Process Execution Language
Web Services - Business Process Execution LanguageMartin Necasky
 
Tutoriál : Otevřená a propojitelná data veřejné správy
Tutoriál : Otevřená a propojitelná data veřejné správyTutoriál : Otevřená a propojitelná data veřejné správy
Tutoriál : Otevřená a propojitelná data veřejné správyMartin Necasky
 
Linked Data for Czech Legislation - 2nd year of our project
Linked Data for Czech Legislation - 2nd year of our projectLinked Data for Czech Legislation - 2nd year of our project
Linked Data for Czech Legislation - 2nd year of our projectMartin Necasky
 
Linked Open Data for Public Contracts
Linked Open Data for Public ContractsLinked Open Data for Public Contracts
Linked Open Data for Public ContractsMartin Necasky
 
Linked Data for Czech Legislation
Linked Data for Czech LegislationLinked Data for Czech Legislation
Linked Data for Czech LegislationMartin Necasky
 
Linked Open Data - Masaryk University in Brno 8.11.2016
Linked Open Data - Masaryk University in Brno 8.11.2016Linked Open Data - Masaryk University in Brno 8.11.2016
Linked Open Data - Masaryk University in Brno 8.11.2016Martin Necasky
 

Andere mochten auch (10)

Web Services - Business Process Execution Language
Web Services - Business Process Execution LanguageWeb Services - Business Process Execution Language
Web Services - Business Process Execution Language
 
Tutoriál : Otevřená a propojitelná data veřejné správy
Tutoriál : Otevřená a propojitelná data veřejné správyTutoriál : Otevřená a propojitelná data veřejné správy
Tutoriál : Otevřená a propojitelná data veřejné správy
 
Linked Data for Czech Legislation - 2nd year of our project
Linked Data for Czech Legislation - 2nd year of our projectLinked Data for Czech Legislation - 2nd year of our project
Linked Data for Czech Legislation - 2nd year of our project
 
Linked Open Data for Public Contracts
Linked Open Data for Public ContractsLinked Open Data for Public Contracts
Linked Open Data for Public Contracts
 
Linked Data for Czech Legislation
Linked Data for Czech LegislationLinked Data for Czech Legislation
Linked Data for Czech Legislation
 
Linked Open Data - Masaryk University in Brno 8.11.2016
Linked Open Data - Masaryk University in Brno 8.11.2016Linked Open Data - Masaryk University in Brno 8.11.2016
Linked Open Data - Masaryk University in Brno 8.11.2016
 
WS-Addressing
WS-AddressingWS-Addressing
WS-Addressing
 
Web Services - WSDL
Web Services - WSDLWeb Services - WSDL
Web Services - WSDL
 
Web Services Tutorial
Web Services TutorialWeb Services Tutorial
Web Services Tutorial
 
Web service introduction
Web service introductionWeb service introduction
Web service introduction
 

Ähnlich wie RESTful Web Services

RESTful for opentravel.org by HP
RESTful for opentravel.org by HPRESTful for opentravel.org by HP
RESTful for opentravel.org by HPRoni Schuetz
 
Restful webservice
Restful webserviceRestful webservice
Restful webserviceDong Ngoc
 
Restful web services rule financial
Restful web services   rule financialRestful web services   rule financial
Restful web services rule financialRule_Financial
 
JAX-RS. Developing RESTful APIs with Java
JAX-RS. Developing RESTful APIs with JavaJAX-RS. Developing RESTful APIs with Java
JAX-RS. Developing RESTful APIs with JavaJerry Kurian
 
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
 
JAX-RS JavaOne Hyderabad, India 2011
JAX-RS JavaOne Hyderabad, India 2011JAX-RS JavaOne Hyderabad, India 2011
JAX-RS JavaOne Hyderabad, India 2011Shreedhar Ganapathy
 
JAX-RS 2.0 and OData
JAX-RS 2.0 and ODataJAX-RS 2.0 and OData
JAX-RS 2.0 and ODataAnil Allewar
 
A Conversation About REST
A Conversation About RESTA Conversation About REST
A Conversation About RESTJeremy Brown
 
OpenTravel Advisory Forum 2012 REST XML Resources
OpenTravel Advisory Forum 2012 REST XML ResourcesOpenTravel Advisory Forum 2012 REST XML Resources
OpenTravel Advisory Forum 2012 REST XML ResourcesOpenTravel Alliance
 
Rest presentation
Rest  presentationRest  presentation
Rest presentationsrividhyau
 
ASP.NET Mvc 4 web api
ASP.NET Mvc 4 web apiASP.NET Mvc 4 web api
ASP.NET Mvc 4 web apiTiago Knoch
 
Building Restful Applications Using Php
Building Restful Applications Using PhpBuilding Restful Applications Using Php
Building Restful Applications Using PhpSudheer Satyanarayana
 
Network Device Database Management with REST using Jersey
Network Device Database Management with REST using JerseyNetwork Device Database Management with REST using Jersey
Network Device Database Management with REST using JerseyPayal Jain
 

Ähnlich wie RESTful Web Services (20)

Rest web services
Rest web servicesRest web services
Rest web services
 
RESTful for opentravel.org by HP
RESTful for opentravel.org by HPRESTful for opentravel.org by HP
RESTful for opentravel.org by HP
 
ReSTful API Final
ReSTful API FinalReSTful API Final
ReSTful API Final
 
ROA.ppt
ROA.pptROA.ppt
ROA.ppt
 
Restful webservice
Restful webserviceRestful webservice
Restful webservice
 
Restful web services rule financial
Restful web services   rule financialRestful web services   rule financial
Restful web services rule financial
 
JAX-RS. Developing RESTful APIs with Java
JAX-RS. Developing RESTful APIs with JavaJAX-RS. Developing RESTful APIs with Java
JAX-RS. Developing RESTful APIs with Java
 
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
 
JAX-RS JavaOne Hyderabad, India 2011
JAX-RS JavaOne Hyderabad, India 2011JAX-RS JavaOne Hyderabad, India 2011
JAX-RS JavaOne Hyderabad, India 2011
 
JAX-RS 2.0 and OData
JAX-RS 2.0 and ODataJAX-RS 2.0 and OData
JAX-RS 2.0 and OData
 
A Conversation About REST
A Conversation About RESTA Conversation About REST
A Conversation About REST
 
OpenTravel Advisory Forum 2012 REST XML Resources
OpenTravel Advisory Forum 2012 REST XML ResourcesOpenTravel Advisory Forum 2012 REST XML Resources
OpenTravel Advisory Forum 2012 REST XML Resources
 
Rest presentation
Rest  presentationRest  presentation
Rest presentation
 
ASP.NET Mvc 4 web api
ASP.NET Mvc 4 web apiASP.NET Mvc 4 web api
ASP.NET Mvc 4 web api
 
Introduction To REST
Introduction To RESTIntroduction To REST
Introduction To REST
 
Building Restful Applications Using Php
Building Restful Applications Using PhpBuilding Restful Applications Using Php
Building Restful Applications Using Php
 
Network Device Database Management with REST using Jersey
Network Device Database Management with REST using JerseyNetwork Device Database Management with REST using Jersey
Network Device Database Management with REST using Jersey
 
REST Basics
REST BasicsREST Basics
REST Basics
 
Rest with Spring
Rest with SpringRest with Spring
Rest with Spring
 

Mehr von Martin Necasky

Otevrena data v CR - aktualni stav (brezen 2013)
Otevrena data v CR - aktualni stav (brezen 2013)Otevrena data v CR - aktualni stav (brezen 2013)
Otevrena data v CR - aktualni stav (brezen 2013)Martin Necasky
 
Web Services - Architecture and SOAP (part 1)
Web Services - Architecture and SOAP (part 1)Web Services - Architecture and SOAP (part 1)
Web Services - Architecture and SOAP (part 1)Martin Necasky
 
Web Services - SOAP (part 2)
Web Services - SOAP (part 2)Web Services - SOAP (part 2)
Web Services - SOAP (part 2)Martin Necasky
 
Otevrene problemy architektury elektronickeho zdravotnictvi
Otevrene problemy architektury elektronickeho zdravotnictviOtevrene problemy architektury elektronickeho zdravotnictvi
Otevrene problemy architektury elektronickeho zdravotnictviMartin Necasky
 
Vysledek souteze o navrh hospodarneho a funkcniho elektronickeho zdravotnictvi
Vysledek souteze o navrh hospodarneho a funkcniho elektronickeho zdravotnictviVysledek souteze o navrh hospodarneho a funkcniho elektronickeho zdravotnictvi
Vysledek souteze o navrh hospodarneho a funkcniho elektronickeho zdravotnictviMartin Necasky
 
Web Services - Introduction
Web Services - IntroductionWeb Services - Introduction
Web Services - IntroductionMartin Necasky
 
Techniky a nástroje pro propojená data (Linked Data)
Techniky a nástroje pro propojená data (Linked Data)Techniky a nástroje pro propojená data (Linked Data)
Techniky a nástroje pro propojená data (Linked Data)Martin Necasky
 
Linked Data pro Evropský sociální fond
Linked Data pro Evropský sociální fondLinked Data pro Evropský sociální fond
Linked Data pro Evropský sociální fondMartin Necasky
 

Mehr von Martin Necasky (8)

Otevrena data v CR - aktualni stav (brezen 2013)
Otevrena data v CR - aktualni stav (brezen 2013)Otevrena data v CR - aktualni stav (brezen 2013)
Otevrena data v CR - aktualni stav (brezen 2013)
 
Web Services - Architecture and SOAP (part 1)
Web Services - Architecture and SOAP (part 1)Web Services - Architecture and SOAP (part 1)
Web Services - Architecture and SOAP (part 1)
 
Web Services - SOAP (part 2)
Web Services - SOAP (part 2)Web Services - SOAP (part 2)
Web Services - SOAP (part 2)
 
Otevrene problemy architektury elektronickeho zdravotnictvi
Otevrene problemy architektury elektronickeho zdravotnictviOtevrene problemy architektury elektronickeho zdravotnictvi
Otevrene problemy architektury elektronickeho zdravotnictvi
 
Vysledek souteze o navrh hospodarneho a funkcniho elektronickeho zdravotnictvi
Vysledek souteze o navrh hospodarneho a funkcniho elektronickeho zdravotnictviVysledek souteze o navrh hospodarneho a funkcniho elektronickeho zdravotnictvi
Vysledek souteze o navrh hospodarneho a funkcniho elektronickeho zdravotnictvi
 
Web Services - Introduction
Web Services - IntroductionWeb Services - Introduction
Web Services - Introduction
 
Techniky a nástroje pro propojená data (Linked Data)
Techniky a nástroje pro propojená data (Linked Data)Techniky a nástroje pro propojená data (Linked Data)
Techniky a nástroje pro propojená data (Linked Data)
 
Linked Data pro Evropský sociální fond
Linked Data pro Evropský sociální fondLinked Data pro Evropský sociální fond
Linked Data pro Evropský sociální fond
 

Kürzlich hochgeladen

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
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
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
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
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
 
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...DianaGray10
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 

Kürzlich hochgeladen (20)

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)
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
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
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
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
 
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...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
+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...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 

RESTful Web Services

  • 1. Web Services (NSWI145) Lecture 07: RESTful Web Services Martin Nečaský, Ph.D. Faculty of Mathematics and Physics Charles University in Prague, Czech Republic
  • 2. What is REST?  REpresentation State Transfer  software architectural style for building distributed hypermedia systems  set of following architectural principles  resource orientation  unique resource identification  stateless client/server interaction  uniform interface  e.g. Web architecture is based on the same principles as REST  but REST principles were derived from the architecture of Web (Roy Fielding dissertation)
  • 3. Principle 1: Resource Orientation  resource = concrete or even abstract thing/action we want to publish  everything is resource in REST  each resource has its representation = document that can be sent between communicating peers  representation format needs to be established • different (meta-)formats may be used (e.g. HTML, XML, JSON, RDF, AtomPub, ...) • each resource can have more representations (in different formats)  representation contains links to related resources • representation format must support links • applications which consume resources navigate instead of calling
  • 4. Principle 2: Unique Resource Identification  each resource has unique ID (name)  universal syntax for resource IDs is necessary, e.g. URI  ID serves not just as a name but also as a means of accessing resource representation  parametrized IDs http://www.company.org/customer?name=John  distinguish resource ID from resource representation ID (e.g. HTML, XML, JSON, RDF documents)  if resource = document then resource ID = resource representation ID  otherwise we need strategy to allow clients to request specific resource representation
  • 5. Principle 2: Unique Resource Identification  direct dereferencing  resource ID is not dereferenceable  client has to know particular resource representation IDs  e.g. Twitter uses direct dereferencing https://api.twitter.com/1/statuses/user_timeline.json https://api.twitter.com/1/statuses/user_timeline.xml
  • 6. Principle 2: Unique Resource Identification  303 URIs  resource ID is dereferenceable  HTTP mechanism  two requests • client requests resource ID and specified preferred resource representation format – server sends resource representation ID • client requests resource representation ID
  • 7. Principle 2: Unique Resource Identification Server GET /customer?name=John Host: www.company.org client Accept: text/xml Server HTTP/1.1 303 See Other Location: client http://www.company.org/customer.xml?name=John Server GET /customer.xml?name=John Host: www.company.org client Accept: text/xml
  • 8. Principle 2: Unique Resource Identification  how to set-up 303 URIs?  e.g. Apache HTTPD (.htaccess file) RewriteCond %{HTTP_ACCEPT} application/rdf+xml RewriteRule ^customer customer.rdf [R=303] http://www.company.org/ http://www.company.org/ customer?name=John customer.xml?name=John
  • 9. Principle 2: Unique Resource Identification  avoid parametrized resource ID  e.g. http://www.company.org/customer/John  instead of http://www.company.org/customer?name=John RewriteCond %{HTTP_ACCEPT} application/rdf+xml RewriteRule ^customer/([a-zA-Z]+)$ customer.rdf?name=John
  • 10. Principle 3: Stateless Client/Server Communication  request/response message exchange  separation of concerns principle  clients separated from servers by interface  clients are not concerned with data storage and (most) application logic  servers are not concerned with user interface or state (server simplicity and scalability)  independent evolution of clients and server  e.g. HTTP request/response, SOAP request/response message exchange pattern, etc.
  • 11. Principle 3: Stateless Client/Server Communication  stateless communication  no state in server-side applications  move state to clients and/or resources  resource state is the same for every client  client changes to resource state affect all other clients  client state is specific for each particular client  communication state
  • 12. Principle 4: Resource Manipulation  uniform interface for resource manipulation  small set of operations which apply for everything • e.g. CRUD operations (Create, Retrieve, Update, Delete)  small set of verbs which apply to large set of nouns • if many applications need new verb, uniform interface can be extended  do not encode verbs into resource identifiers http://www.company.org/addCustomer?name=John
  • 13. Principle 4: Resource Manipulation  when HTTP protocol is used, following four operations are usually considered  GET = requests representation of the specified resource • read-only operation, should be safe = should not cause any side- effects  PUT = uploads representation of the specified resource • write operation, should be idempotent – idempotent = may cause side effects but its multiple calls cause the same effect – being idempotent means being simple = identical request causes the same state change independently of how many times it has been called  DELETE = deletes the specified resource • write operation, should be idempotent  POST = submits data to be processed to the specified resource • it can update the resource • generally not safe and not idempotent
  • 14. RESTful Web Services  RESTful Web Service  enables manipulation with set of resources  typically uses XML, JSON or RDF for resource representation  uses URLs as resource identifiers  stateless  HTTP methods GET/PUT/DELETE/POST for resource manipulation  like Web application but for machines instead of humans
  • 15. RESTful Web Services Operation Resource representing Resource representing collection of individuals individual GET List members in collection Retrieve individual • e.g. weekly list public contracts • e.g. retrieve public contract PUT Update collection with Update individual another one • e.g. update public contract • e.g. replace weekly list of representation with new public contracts at the representation beginning of new week DELETE Delete entire collection Delete individual • e.g. delete weekly list of • e.g. delete public contract public contracts POST Create member of Create part of individual collection with auto-ID • e.g. create public contract • e.g. add new public contract to tender the collection and generate its ID
  • 16. JAX-RS (Jersey Impl.) with Tomcat + Eclipse  download Jersey  https://jersey.dev.java.net/  (A zip of Jersey containing the Jersey jars, core dependencies (it does not provide dependencies for third party jars beyond those for JSON support) and JavaDoc)  create new Eclipse Dynamic Web Project ProjectName  Apache Tomcat as Target runtime  ProjectName project > Properties  Java Build Path > Libraries > Add External JARs... • add JARs from Jersey zip  copy JARs from Jersey zip to WEB-INF/lib  modify WEB-INF/web.xml
  • 17. JAX-RS (Jersey Impl.) with Tomcat + Eclipse  class PublicContracts01 in Procurement_REST_WS project  http://localhost:8080/Procurement_REST_WS/res ources/PublicContracts01/  provides simple representation of “List of public contracts” resource in plain text, HTML and XML  basic JAX-RS annotations • @Path • @GET • @Produces
  • 18. JAX-RS (Jersey Impl.) with Tomcat + Eclipse  test with cURL (curl_PublicContracts01.bat)  http://curl.haxx.se/download.html
  • 19. JAX-RS (Jersey Impl.) with Tomcat + Eclipse  class PublicContracts02 in Procurement_REST_WS project  http://localhost:8080/Procurement_REST_WS/resources/Public Contracts02/  getPublicContract method which returns XML or JSON representation of public contract to GET request • class PublicContract • JAXB annotation (provides XML and JSON binding) – @XmlRootElement  listContracts method returns XML or JSON representation of all public contracts in collection to GET request  listContractsHTML method returns HTML representation of all public contracts in collection to GET request  JAX-RS annotations • @Path – path with path parameter • @PathParam – association of path parameter with method parameter
  • 20. JAX-RS (Jersey Impl.) with Tomcat + Eclipse  test  http://localhost:8080/Procurement_REST_WS/res ources/PublicContracts02/  http://localhost:8080/Procurement_REST_WS/res ources/PublicContracts02/4
  • 21. JAX-RS (Jersey Impl.) with Tomcat + Eclipse  class PublicContracts03 in Procurement_REST_WS project  http://localhost:8080/Procurement_REST_WS/res ources/PublicContracts03/  putPublicContract updates existing or creates new public contract  deletePublicContract deletes existing public contract  JAX-RS annotations • @PUT • @DELETE
  • 22. JAX-RS (Jersey Impl.) with Tomcat + Eclipse  test with cURL (curl_PublicContracts03.bat)
  • 23. JAX-RS (Jersey Impl.) with Tomcat + Eclipse  class PublicContracts04 in Procurement_REST_WS project  http://localhost:8080/Procurement_REST_WS/res ources/PublicContracts04/  createPublicContract creates new contract on POST request  JAX-RS annotations • @POST
  • 24. JAX-RS (Jersey Impl.) with Tomcat + Eclipse  test with form_PublicContracts04.html