Agenda

  • Motivation
  • REST Conceptual Overview
  • REST Web Service Technologies
    • HTTP
    • XML
    • JSON
    • AJAX
    • WADL
  • Illustration by a larger example
  • Extensions
  • Summary
  • Resources
 


Motivation Examples

  •  YouTube video portal - free upload and download of videos
    • Exceeds 2 billion views a day1
    • 24 hours of video uploaded every minute
    • 70% of YouTube’s traffic comes from outside the U.S.
    • Google paid 1.6 Billion dollars for YouTube in 2006.


The need for Web 2.0 services?

  • Large quantities of data are on the Web
    • The data needs to be managed in an appropriate manner.
    • Retrieved, queried, analyzed, transformed, transferred, stored, etc.
  • Easy integration of data and services
    • Web apps should work with the other Web apps
      • LinkedIn can import your
      • Facebook can import your Dopplr trips 
    • Mashups should be enabled
      • Easy service composition
    • Desktop apps should work with Web apps
      • Flickr uploadr , Google calendar update/sync
  • Technical solutions are needed to enable a truly Programmable Web
    • The solution can be seen in the form of Web 2.0 services (a.k.a. Web APIs)
  • Data providers are offering Web APIs
    • Web 2.0 services enabling easy access to the Web 2.0 data.
      • Google maps, Geonames, phone location…
      • Microformats (vcard, calendar, review…)
      • Data feeds  
    • Various functionalities are supported through Web APIs 
      • Publishing, messaging, payment…
    • Web 2.0 facilitates user involvement through “reverse” APIs (leveraging on human computation)
      • Amazon Mechanical Turk, ESP game… 
    • Overall Web APIs are powering the vision of the Web 2.0 as a collaborative and computational platform 



    Requirements

    • Requirements supported by Web APIs stem from the requirements addressed by any system following Web architecture: 
      • Simplicity
        • Low barrier of entry, fast adoption of Web APIs.
      • Extensibility
        • Allowing growth, flexibility, and composition.
      • Distributed hypermedia
        • Relying on the established concepts of hyperlinked content already accepted by Web users.
      • Scalability at the Web level
        • Should rely on technologies/protocols supporting scalable solutions.
      • Independent deployment
        • Coexistence of old and new


    Representational State Transfer (REST)

    • The requirements for WebAPIs are met by Representational State Transfer (REST)
      • A style of software architecture for distributed hypermedia systems such as the World Wide Web.
    • REST is basically client/server architectural style
      • Requests and responses are built around the transfer of "representations" of Web "resources".
    • HTTP is the main and the best example of a REST style implementation
      • But it should not be confused with REST


    RESTful Web Service definition

    • Another way of realizing services, other then SOAP/WSDL/UDDI approach
      • Closely follows the Web principles (REST principles)
    • A RESTful Web service...
      • ... exposes its data and functionality through interlinked Web resources indentified by URI and meant to be consumed by an autonomous program (i.e., machine).
      • ... is more data-centric, and less functionality-centric (as opposed to SOAP services).
      • ... embeds functionality of the service in the uniform HTTP interfaces for interaction: GET, PUT, DELETE, POST.
      • ... uses HTTP as the application protocol instead of SOAP
    • Like a Web application, but for machines.
    • Like WS-*, but focused on Web resources (i.e., data).
      WS-* stands for a variety of specifications related to SOAP-based Web Services.


    WS-* vs REST: A quick comparison

    • A SOAP service (WS-*) has a single endpoint that handles all the operations
      • It has to have an application-specific interface.
      • Functionality is hidden behind the interface.
      • Data is processed “behind” the interface by a service implementation.
      • The focus is on the functionality.
    • A RESTful service has a number of Web resources, so the operations are distributed over the resources
      • The functionality is “embedded and intertwined” with the data interaction protocol (i.e., HTTP).
      • The focus is on the data.
      • Data is “close” to the prosumer.


    Overview

    • Hotel booking workflow includes following steps:
      • Retrieve service description
        • Getting to know how to use the RESTful service
        • Usually written in natural text on some Web page
      • Submit search criteria according to description
      • Retrieve linked details of interesting hotels
      • Submit payment details according to selected rate description
      • Retrieve confirmation of booking
      • Retrieve list of user's bookings


    Hypermedia model



    WSDL model




    WS-* vs RESTful



    Technologies

    • Todays’s set of technologies used to empower RESTful paradigm:
      • HTTP as the basis,
      • XML and JSON for data exchange, and
      • AJAX for client-side programming (e.g. browser).
    • There exists an attempt to develop WSDL-like definition language for describing RESTful services
      • Web Application Description Language (WADL)


    Overview

    • HTTP
      • A protocol for distributed, collaborative, hypermedia information systems.
      • A request/response standard typical of client-server computing.
      • Currently dominant version is HTTP/1.1.
    • Massively used to deliver content over the Web
      • Web browsers and spiders are relying on HTTP.
    • The protocol is not constrained to TPC/IP
      • It only presumes a reliable transport.
    • Resources accessed by HTTP are identified by URIs (more specifically URLs), using the http URI schemes. 


    HTTP Request-response format

    • Request consists of
      • Request line, such as GET /images/logo.gif HTTP/1.1, which requests are source called /images/logo.gif from server.
      • Headers, such as Accept-Language: en
      • An empty line
      • An optional message body
    • Response consists of
      • Status line which includes numeric status code and textual reason phrase
      • Response headers
      • An empty line
      • The requested content


    HTTP Request methods

     
    • HTTP request methods indicate the desired action to be performed on the identified resource:           
      • GET
        • Requests a representation of the specified resource. GET should not be used for operations that cause side-effects (problematic with robots and crawlers). Those operations are called safe operations.
      • POST
        • Submits data to be processed (e.g., from an HTML form) to the identified resource. The data is included in the body of the request.
      • PUT
        • Uploads a representation of the specified resource.
      • DELETE
        • Deletes the specified resource.


    HTTP Example – Retrieving FOAF profile

    • Example is relying on curl which is a command line tool used to transfer data with URL syntax
      • Supports many protocols such as FTP, FTPS, HTTP, HTTPS, SCP, SFTP, etc.
      • More information can be found at http://curl.haxx.se
    • curl usage pattern is simple:

      $ curl -v http://www.google.at
      * About to connect() to www.google.at port 80 (#0)
      * Trying 74.125.87.104... connected
      * Connected to www.google.at (74.125.87.104) port 80 (#0)
      > GET / HTTP/1.1
      > User-Agent: curl/7.19.6 (i686-pc-cygwin) libcurl/7.19.6 OpenSSL/0.9.8o zlib/1.2.3 libidn/1.18 libssh2/1.2
      > Host: www.google.at
      > Accept: */*
      >
      < HTTP/1.1 200 OK
      < Date: Sun, 13 Jun 2010 15:13:15 GMT
      < Expires: -1
      < Cache-Control: private, max-age=0
      < Content-Type: text/html; charset=ISO-8859-1
      < Set-Cookie: PREF=ID=29937d127162f98f:TM=1276441995:LM=1276441995:S=wQcvUApkDnuGPQEa; expires=Tue, 12-Jun-2012 15:13:15
      < Server: gws
      < X-XSS-Protection: 1; mode=block
      < Transfer-Encoding: chunked
      <



    HTTP Example – Retrieving FOAF profile

    Srdjans-MacBook-Pro:~ skomazec$ curl -v http://www.sti-innsbruck.at/fileadmin/scripts/foaf.php?id=215

    * About to connect() to www.sti-innsbruck.at port 80 (#0)

    * Trying 138.232.65.141... connected* Connected to www.sti-innsbruck.at (138.232.65.141) port 80 (#0)

    > GET /fileadmin/scripts/foaf.php?id=215 HTTP/1.1

    > User-Agent: curl/7.19.7 (universal-apple-darwin10.0) libcurl/7.19.7 OpenSSL/0.9.8l zlib/1.2.3

    > Host: www.sti-innsbruck.at

    > Accept: */*

    < HTTP/1.1 200 OK

    < Date: Sun, 06 Jun 2010 15:55:57 GMT

    < Server: Apache

    < X-Powered-By: PHP/5.2.0-8+etch16

    < Content-Length: 944

    < Content-Type: text/html; charset=UTF-8

    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"

    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"

    xmlns:foaf="http://xmlns.com/foaf/0.1/">

    Srdjan Komazec

    Srdjan

    Komazec

    7348d8f19c568de04c7718880f700fad7acdfab9

    * Connection #0 to host www.sti-innsbruck.at left intact

    * Closing connection #0

    Requested resource



    Overview

    • eXtensible Markup Language (XML) 
      • A set of rules for encoding documents electronically. 
      • De-facto standard (W3C Recommendation).
    • Ubiquitous presence on the Web and the Semantic Web
      • Storage and transportation of data (RDF/XML and SOAP),
      • Visualization of data (XHTML),
      • Application configuration (XML configuration files), etc.
    • As such it can not be avoided as a possible data format for Web 2.0 Web Services. 



    XML Characteristics

    • As opposed to JSON XML can be verified against a schema expressed in a number of languages such as Document Type Definition (DTD), and XML Schema:
      • the vocabulary (element and attribute names),
      • the content model (relationships and structure), and
      • the data types.
    • Founded on the standards laying in the core of Web
      • Uniform Resource Identifiers (URI)
      • Unicode
    • Well-formedness an XML document
      • Properly encoded legal Unicode characters,
      • Special syntax characters such as < and & are used only as markup delineation,
      • Element tags are correctly nested,
      • Element tags are case sensitive,
      • There exists a single “root” element.


    XML Example

      
    <?xml version="1.0" encoding="UTF-8"?> <Person> <firstName>John</firstName> <lastName>Smith</lastName> <age>25</age> <address> <streetAddress>21 2nd Street</streetAddress> <city>New York</city> <state>NY</state> <postalCode>10021</postalCode> </address> <phoneNumber type="home">212 555-1234</phoneNumber> <phoneNumber type="fax">646 555-4567</phoneNumber> <newSubscription>false</newSubscription> <companyName /> </Person>


    Overview

    • JavaScript Object Notation (JSON)
      • A lightweight computer data interchange format.
      • Specified in Request For Comment (RFC) 4627.
    • Represents a simple alternative to XML
      • A text-based, human-readable format for representing simple data structures and associative arrays (called objects).
    • Used by a growing number of services
    • JavaScript-friendly notation
      • Its main application is in Ajax Web application programming.
    • A serialized object or array
    • No namespaces, attributes etc.
    • No schema language (for description, verification)


    Data types

    • Number (integer, real, or floating point)
    • String (double-quoted Unicode with backslash escaping)
    • Boolean (true and false)
    • Array (an ordered sequence of values, comma-separated and enclosed in square brackets)
    • Object (collection of key:value pairs, comma-separated and enclosed in curly braces)
    • null



    Example

    {

      "firstName": "John",

      "lastName": "Smith",

      "age": 25,

      "address":{

      "streetAddress": "21 2nd Street",

      "city": "New York",

      "state": "NY",

      "postalCode": "10021",

      },

      "phoneNumbers": [

      {"type": "home", "number": "212 555-1234"},

      {"type": "fax", "number": "646 555-4567"}

      ],

      "newSubscription": false,

      "companyName": null

    }


    Overview

    • Asynchronous JavaScript and XML (AJAX)
      • A group of interrelated web development techniques used on the client-side to create interactive web applications
      • Web apps can fetch data from the server without refreshing the page 
    • AJAX is used to increase interactivity and dynamism of web pages
    • Since the technological base is partially shared AJAX and RESTful services make a good match
      • Enriching Web pages with the data operated through RESTful services


    AJAX Constituent technologies

    • (X)HTML and CSS
      • Information styling and marking.
    • Document Object Model (DOM)
      • A cross-platform and language-independent convention for representing and interacting with objects in HTML, XHTML and XML documents.
      • Objects are accessed through JavaScript
    • XMLHttpRequest object
      • Present in all major browsers
      • Method to exchange data between the server and browser in async manner
    • XML or JavaScript Object Notation - JSON
      • Interchange, manipulation and display of data.
    • JavaScript
      • Language which brings all these technologies together


    Overview

    • Web Application Description Language
      • No real uptake
      • W3C Member Submission
    • Application ( = our Web service)
      • Has resources
      • Resources have HTTP methods
      • Inputs and outputs can contain links to resources
    • WADL focuses on resources and hypertext
      • As opposed to operations (WSDL)


    Example



    Twitter REST API

    • Twitter is social networking and microblogging service that enables its users to send and read messages known as tweets.
    • Tweets are text-based posts of up to 140 characters displayed on the author's profile page and delivered to the author's subscribers who are known as followers.
    • Twitter has offered a comprehensive set of RESTful APIs to access core Twitter data: update timelines, status data and user information.
    • User sensitive data is protected by the HTTP Basic authentication mechanism.


    Twitter REST API – Retrieve User Timeline

    • Retrieves collection of 20 most recent tweets posted by user.

    Method:

    statuses/user_timeline

    Description:

    Returns the 20 most recent statuses posted from the authenticated user. It's also possible to request another user's timeline via the id parameter.

    URL:

    http://api.twitter.com/1/statuses/user_timeline.format

    Formats:

    xml, json, rss, atom

    HTTP Method:

    GET

    Parameters:

    id

    optional

    Specifies the ID or screen name of the user for whom to return the user timeline.

    since_id

    optional

    Returns only statuses with an ID greater than (that is, more recent than) the specified ID.

    max_id

    optional

    Returns only statuses with an ID less than (that is, older than) or equal to the specified ID.



    Twitter REST API – Retrieve User Timeline

    Srdjans-MacBook-Pro:~ skomazec$ curl -v http://api.twitter.com/1/statuses/user_timeline/google.xml * About to connect() to api.twitter.com port 80 (#0) * Trying 168.143.162.45... connected * Connected to api.twitter.com (168.143.162.45) port 80 (#0) > GET /1/statuses/user_timeline/google.xml HTTP/1.1 > User-Agent: curl/7.19.7 (universal-apple-darwin10.0) libcurl/7.19.7 OpenSSL/0.9.8l zlib/1.2.3 > Host: api.twitter.com > Accept: */* > < HTTP/1.1 200 OK < Date: Sun, 06 Jun 2010 16:04:48 GMT < Server: hi < Status: 200 OK … < Vary: Accept-Encoding < Connection: close < <?xml version="1.0" encoding="UTF-8"?> <statuses type="array"> <status> <created_at>Sat Jun 05 15:24:45 +0000 2010</created_at> <id>15493557859</id> <text>#subsaturday @youtube channels: Forbes http://goo.gl/BKnh; NHLvideo http://goo.gl/kGlK; CelebrityPlaylists http://goo.gl/BL1y</text> <source>web</source> <truncated>false</truncated> <in_reply_to_status_id></in_reply_to_status_id> <in_reply_to_user_id></in_reply_to_user_id> <favorited>false</favorited> <in_reply_to_screen_name></in_reply_to_screen_name> <user> <id>20536157</id> <name>A Googler</name> <screen_name>google</screen_name> <location>Mountain View, CA</location> <description>News and updates from Google</description> <profile_image_url>http://a3.twimg.com/profile_images/77186109/favicon_normal.png</profile_image_url> <url>http://www.google.com/support/</url> …


    Twitter REST API – Showing Single Tweet

    • Retrieves a single tweet.
    • Status is a Web resource!!!

    Method:

    statuses/show

    Description:

    Returns a single status, specified by the id parameter below.  The status's author will be returned inline.

    URL:

    http://api.twitter.com/1/statuses/show/id.format

    Formats:

    xml, json

    HTTP Method:

    GET

    Parameters:

    id

    required

    The numerical ID of the status to retrieve.



    Twitter REST API – Showing Single Tweet

    Srdjans-MacBook-Pro:~ skomazec$ curl -v http://api.twitter.com/1/statuses/show/9627441680.xml * About to connect() to api.twitter.com port 80 (#0) * Trying 128.242.245.93... connected * Connected to api.twitter.com (128.242.245.93) port 80 (#0) > GET /1/statuses/show/9627441680.xml HTTP/1.1 > User-Agent: curl/7.19.7 (universal-apple-darwin10.0) libcurl/7.19.7 OpenSSL/0.9.8l zlib/1.2.3 > Host: api.twitter.com > Accept: */* > < HTTP/1.1 200 OK < Date: Sun, 06 Jun 2010 16:09:31 GMT < Server: hi < Status: 200 OK < X-Transaction: 1275840571-6663-24393 < X-RateLimit-Limit: 150 … < Vary: Accept-Encoding < Connection: close < <?xml version="1.0" encoding="UTF-8"?> <status> <created_at>Thu Feb 25 14:23:37 +0000 2010</created_at> <id>9627441680</id> <text>From our European public policy blog, Amit Singhal explains just how tough search is: http://bit.ly/9UbBSD</text> <source>&lt;a href=&quot;http://bit.ly&quot; rel=&quot;nofollow&quot;&gt;bit.ly&lt;/a&gt;</source> <truncated>false</truncated> … <user> <id>20536157</id> <name>A Googler</name> <screen_name>google</screen_name> <location>Mountain View, CA</location> <description>News and updates from Google</description> <profile_image_url>http://a3.twimg.com/profile_images/77186109/favicon_normal.png</profile_image_url> <url>http://www.google.com/support/</url> <protected>false</protected> <followers_count>2266241</followers_count> …


    Twitter REST API – Posting new Tweet

    • Posts a new tweet.

    Method:

    statuses/update

    Description:

    Updates the authenticated user's status.  Requires the status parameter specified below.  A status update with text identical to the authenticated user's current status will be ignored to prevent duplicates.

    URL:

    http://api.twitter.com/1/statuses/update.format

    Formats:

    xml, json

    HTTP Method:

    POST

    Parameters:

    status

    required

    The text of your status update. URL encode as necessary.

    lat

    optional

    The location's latitude that this tweet refers to.

    long

    optional

    The location's longitude that this tweet refers to.

    in_reply_to_status_id

    optional

    The ID of an existing status that the update is in reply to.



    Twitter REST API – POST example

     

    <?xml version="1.0" encoding="UTF-8"?> <status> <created_at>Sun Jun 06 16:30:08 +0000 2010</created_at> <id>15566102131</id> <text>APITest</text> <source>&lt;a href=&quot;http://apiwiki.twitter.com/&quot; rel=&quot;nofollow&quot;&gt;API&lt;/a&gt;</source> <truncated>false</truncated> <in_reply_to_status_id></in_reply_to_status_id> <in_reply_to_user_id></in_reply_to_user_id> <favorited>false</favorited> <in_reply_to_screen_name></in_reply_to_screen_name> <user> <id>20307518</id> <name>Srdjan Komazec</name> <screen_name>skomazec</screen_name> <location>Innsbruck, Austria</location> <description></description> <profile_image_url>http://s.twimg.com/a/1275689140/images/default_profile_0_normal.png</profile_image_url> <url></url> <protected>false</protected> … <friends_count>3</friends_count> <created_at>Sat Feb 07 12:51:45 +0000 2009</created_at> <favourites_count>0</favourites_count> <utc_offset>3600</utc_offset> <time_zone>Vienna</time_zone> … </user> <geo/> <coordinates/> <place/> <contributors/> </status>


    Mashup –Wheather Bonk

    • Rich mashup with live weather, forecasts, webcams, and more on a Google Map.
    • Relies on a number of RESTful APIs
      • Google AdWords
      • Google Maps
      • hostip.info
      • Microsoft Virtual Earth
      • NASA
      • NOAA Weather Service
      • WeatherBug
      • Yahoo Geocoding
      • Yahoo Maps
      • Yahoo Traffic


    Mashup –Wheather Bonk (cont')





    Extensions

    • Semantic descriptions of RESTful services
      • hRESTS like a simplified WSDL to annotate Web pages describing service functionality
      • MicroWSMO adds semantic annotations (like SAWSDL)
      • Annotations can target WSMO-Lite descriptions
    • Discovery of RESTful services
      • Methods to analyze JavaScript in AJAX sites
      • The present trend is to pack RESTful functionality in the form of JavaScript libraries
        • E.g., Google AJAX Search API (http://code.google.com/apis/ajaxsearch)
      • Analysis of the code could unveil information about the used services


    Summary

    •   Web 2.0 technologies are ubiquitously present on today’s Web
      • Users are dominant producers of data.
      • Data is opened for further processing and integration.
    • Representational State Transfer (REST) is an architectural style especially suitable to exploit the Web of data and offer services on top of the data
      • The RESTful systems are compliant with the Web requirements.
      • REST brings the data residing on the Web near to the prosumers and the ways to process it.
    • RESTful-approach represents a natural way to offer Web Services as opposed to the SOAP-based Web Services
      • It builds on top of the architectural style which pervades the Web
      • It relies on the proven Web protocol (HTTP) and data formats (XML, JSON).
      • It integrates easily with the dominant visualization tool (a.k.a. Web browser) through JavaScript and AJAX.
    • RESTful-based services are dominating the Service Web
      • 68% RESTful services vs. 19% SOAP services*.
      • It is expected that the dominance of RESTful services will grow up in future.

    Sources
    *Statistics retrieved from the Programmable Web on Dec 17th, 2009 @ http://www.programmableweb.com/apis (originally from slide slide Summary)

    References

    • Fielding, Roy T.; Taylor, Richard N. (2002-05), "Principled Design of the Modern Web Architecture”, ACM Transactions on Internet Technology (TOIT) (New York: Association for Computing Machinery) 2 (2): 115–150
    • Fielding, Roy Thomas (2000), Architectural Styles and the Design of Network-based Software Architectures, Doctoral dissertation, University of California, Irvine
    • Web 2.0: http://en.wikipedia.org/wiki/Web_2.0
    • REST: http://en.wikipedia.org/wiki/REST 
    • JavaScript: http://en.wikipedia.org/wiki/Javascript 
    • AJAX: http://en.wikipedia.org/wiki/AJAX 
    • JSON: http://en.wikipedia.org/wiki/JSON 
    • Atom: http://en.wikipedia.org/wiki/Atom_(standard)
    • Mashups: http://en.wikipedia.org/wiki/Mashup_(web_application_hybrid)
    • HTTP: http://tools.ietf.org/html/rfc2616




    Creator: sidraaslam

    Contributors:
    -


    Licensed under the Creative Commons
    Attribution ShareAlike CC-BY-SA license


    This deck was created using SlideWiki.