The Internet as Web Services: introduction to ReST

download The Internet as Web Services: introduction to ReST

If you can't read please download the document

Transcript of The Internet as Web Services: introduction to ReST

The Internet as Web Services: introduction to ReST

The Internet
as Web Services:
introduction to ReST

Oscar Zambotti is a student of Information Technology at the Faculty of Science, University of Trento.He attended the 9-months course "ICT secure programming expert" in Bozen offered by the European Social Fund.Now he's in FBK for his stage period in the SoNet Group and following the Presentation or die motto is giving this presentation in the very beginning of his stage.Oscar is very interested in social networking and programming applications about it. He is also a speaker and DJ in a local radio station.http://[email protected]

Bio

The Internet as Web Services: introduction to ReST Oscar Zambotti, 2009

What is a Web Service?

Different ways: SOAP and ReST

Examples: Twitter and Flickr

How am I going to use ReST?

What am I going to talk about?

The Internet as Web Services: introduction to ReST Oscar Zambotti, 2009

1. What is a Web Service?

The Internet as Web Services: introduction to ReST Oscar Zambotti, 2009

The challenge now is to join forces to research on Software & Services Technologies, to bring advances to the market and to ensure European leadership in the new Internet economy: The Internet of Services.Internet of Services, Software and Virtualisation - Objective ICT 2009.1.2, Call 5 of the Seventh Framework Programme (2007-2013)
European Commission - Information Society and Media

The Internet has shown remarkable resilience and flexibility in the face of ever increasing numbers of users, data volume, and changing usage patterns, but faces growing challenges in meetings the needs of our knowledge society. This is the moment to start designing the Internet of the Future.Future Internet - Research programs of the CIT (Center for Innovation Technology)
Fondazione Bruno Kessler

The vision of the Future Internet

A Web Service (WS) is a software system designed to support interoperable machine-to-machine interaction over a network. - W3C GlossaryUsually a WS provides the API (Application Programming Interface).

Hardware limitations?

Languages limitations?

Access limitations?

What is a web service?

The Internet as Web Services: introduction to ReST Oscar Zambotti, 2009

Use of web services? E.g. Flickrvision

The Internet as Web Services: introduction to ReST Oscar Zambotti, 2009

Flickr photos with Google Maps

A mashup is a Web application that combines data or functionality from one or more sources into a single integrated application.http://www.programmableweb.com

The Internet as Web Services: introduction to ReST Oscar Zambotti, 2009

Web services for mashups

The Internet as Web Services: introduction to ReST Oscar Zambotti, 2009

ProgrammableWeb statistics

1308 APIs3957 Mashups(12 May 2009)

The trend...

2. Different ways:
SOAP and ReST

SOAP (Simple Object Access Protocol) uses XML and RPC or HTTP.Businesses can register their WS on UDDI
(Universal Description, Discovery
and Integration) and provide
documentation with WSDL
(Web Services
Description Language)

The Internet as Web Services: introduction to ReST Oscar Zambotti, 2009

image: WikipediaHow to use a web service: SOAP

image: Wikipedia




classifieds


The Internet as Web Services: introduction to ReST Oscar Zambotti, 2009

How to use a web service: SOAP /2

Sample:
Request...





http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous




http://localhost:8080/axis2/services/MyService



ECE5B3F187F29D28BC11433905662036




classifieds


The Internet as Web Services: introduction to ReST Oscar Zambotti, 2009

How to use a web service: SOAP /3

...Response

ReST (Representational State Transfer) is an architectural style for distributed hypermedia systems, it is not just a method for building web services.Introduced by Roy Thomas Fielding in his dissertation to become Ph.D. in 2000.Resource URI
Interaction RepresentationAn application can interact with a resource by knowing the identifier of the resource (URI), and the action required (HTTP methods). ReST is stateless.

How to use a web service: ReST

The Internet as Web Services: introduction to ReST Oscar Zambotti, 2009

HTTP consists in URIs, methods, status codes...The most important HTTP methods compose the basic functions in computer science: CRUD

How to use a web service: ReST /2

The Internet as Web Services: introduction to ReST Oscar Zambotti, 2009

HTTPCRUDSQL

POSTCreateINSERT

GETReadSELECT

PUTUpdateUPDATE

DELETEDeleteDELETE

http://example.com/losties

How to use a web service: ReST /3

The Internet as Web Services: introduction to ReST Oscar Zambotti, 2009

POST
- Create -GET
- Read -PUT
- Update -DELETE
- Delete -

Create a new passengerList

http://example.com/losties/4815162342

Response format: HTML, XML (RSS, Atom, custom), JSON, ...

Suggested reading: How I explained ReST to my wife (Ryan Tomayko)

POST
- Create -GET
- Read -PUT
- Update -DELETE
- Delete -

Passenger dataUpdate passenger dataDelete passenger

An application is ReSTful when has resources accessible by representations.http://example.com/losties/4815162342

Some services are ReST-like: you use HTTP methods but using APIs methods as parameters (Flickr).http://example.com/losties/getLostie?id=4815162342

Nouns vs Verbs

How to use a web service: ReST /4

The Internet as Web Services: introduction to ReST Oscar Zambotti, 2009

A large number of developers
chooses ReST instead of SOAP.

The Internet as Web Services: introduction to ReST Oscar Zambotti, 2009

SOAP vs. ReST on ProgrammableWeb

3. ReST examples
(Python code)

What is Twitter?

Example: Twitter

The Internet as Web Services: introduction to ReST Oscar Zambotti, 2009

Twitter REST API Method: statuses/show
Returns a single status, specified by the id parameter below. The status's author will be returned inline.URL:
http://twitter.com/statuses/show/id.formatFormats: xml, json, rss, atomHTTP Method(s): GETRequires Authentication:
false, unless the author of the status is protected

Example: Twitter /2

The Internet as Web Services: introduction to ReST Oscar Zambotti, 2009

Twitter REST API Method: statuses/update
Updates the authenticating user's status. Requires the status parameter specified below. Request must be a POST. A status update with text identical to the authenticating user's current status will be ignored to prevent duplicates.URL:
http://twitter.com/statuses/update.formatFormats: xml, json, rss, atomHTTP Method(s): POSTRequires Authentication: true

http://apiwiki.twitter.com/Twitter-API-DocumentationSome methods require authentication (OAuth)

import httplib
# some code...def fetch_following(self):
conn = httplib.HTTPConnection("twitter.com")
conn.request("GET","/friends/ids/"+self.screen_name+".json")
r1 = conn.getresponse()
print r1.read()
conn.close()

Example: Twitter /3

The Internet as Web Services: introduction to ReST Oscar Zambotti, 2009

Output (sample!): user IDs[5428712,31528501,6603122,30304051,30303627,5159271,
17572031,15147484]

Obj: fetch the list of the user IDs that a user is following

What is Flickr?Screenshot

Example: Flickr

The Internet as Web Services: introduction to ReST Oscar Zambotti, 2009

Developers need a couple of keys to use the APIs.Some methods require authentication.

Example: Flickr /2

The Internet as Web Services: introduction to ReST Oscar Zambotti, 2009

REST Request FormatREST is the simplest request format to use - it's a simple HTTP GET or POST action.The REST Endpoint URL is http://api.flickr.com/services/rest/To request the flickr.test.echo service, invoke like this:
http://api.flickr.com/services/rest/?method=flickr.test.echo&name=valueBy default, REST requests will send a REST response.

Example: Flickr /3

The Internet as Web Services: introduction to ReST Oscar Zambotti, 2009

http://www.flickr.com/services/api/

Some methods require authentication.

import urllib, urllib2, jsonFRI = "http://api.flickr.com/services/rest/?"
KEY = "d00fa386476950f75555555555555555"
SECRET = "cac879e555555555"
FORMAT = "json"# some code...def people_find_by_username(username):
# some code...def contacts_get_public_list(username):

nsid = people_find_by_username(username) req = {'method': CONTACTS_GETPUBLICLIST, 'api_key': KEY,
'user_id': nsid, 'format': FORMAT, 'nojsoncallback': 1}
params = urllib.urlencode(req)
contacts_public_list =
urllib2.urlopen(FRI,params).read()
print contacts_public_list

Example: Flickr /4

The Internet as Web Services: introduction to ReST Oscar Zambotti, 2009

HTTP POST (implicit)

Obj: fetch the list of the friends a user

Example: Flickr /5

The Internet as Web Services: introduction to ReST Oscar Zambotti, 2009

Output (sample!): collection (dictionaries, lists){"contacts":
{"page":1, "pages":1, "per_page":1000, "perpage":1000,
"total":39, "contact":
[{"nsid":"81107858@N00", "username":"Jack",
"iconserver":"207", "iconfarm":1, "ignored":0},
{"nsid":"23578585@N00", "username":"Locke",
"iconserver":"211", "iconfarm":1, "ignored":0},
{"nsid":"81158128@N00", "username":"Sawyer",
"iconserver":"147", "iconfarm":1, "ignored":0},
{"nsid":"29563291@N00", "username":"Hurley",
"iconserver":"182", "iconfarm":1, "ignored":0},
{"nsid":"20347812@N00", "username":"Kate",
"iconserver":"113", "iconfarm":1, "ignored":0}]}, "stat":"ok"}

4. How am I going to use ReST?

Web-based tool, with prepopulation using Web APIs, that displays the network of a user and its evolution over some social networks before and after a defined event.

What am I going to do? Socialdash

The Internet as Web Services: introduction to ReST Oscar Zambotti, 2009

Questions?Ideas?Suggestions?

Thanks

The Internet as Web Services: introduction to ReST Oscar Zambotti, 2009

http://sonet.fbk.eu

European Commission: Seventh Framework Programme
http://cordis.europa.eu/fp7
http://cordis.europa.eu/fp7/ict/programme/challenge1_en.html

Strategic guidelines in FBK: the Future Internethttp://cit.fbk.eu/future_internet

W3C Glossary
http://www.w3.org/TR/ws-gloss/

Representational State Transfer (ReST) by Roy Thomas Fielding
http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htmhttp://www.ics.uci.edu/~fielding/

Suggested readings:
http://tomayko.com/writings/rest-to-my-wife

Bibliography

The Internet as Web Services: introduction to ReST Oscar Zambotti, 2009

Muokkaa otsikon tekstimuotoa napsauttamalla

Muokkaa jsennyksen tekstimuotoa napsauttamallaToinen jsennystasoKolmas jsennystasoNeljs jsennystasoViides jsennystasoKuudes jsennystasoSeitsems jsennystasoKahdeksas jsennystasoYhdekss jsennystaso