Download presentation
1
Introduction to Web Services
Asst. Prof. Chaiporn Jaikaeo, Ph.D. Computer Engineering Department Kasetsart University, Bangkok, Thailand
2
Traditional World-Wide-Web
Designed for human-to-app interactions Information sharing (Non-automated) E-commerce Built on top of HTTP – for data transfer HTML – for representing document
3
What's Next? Try taking humans out of the loop
Systematic application-to-application interaction over the web Automated e-commerce Resource sharing Distributed computing Web services (another) effort to build distributed computing platform for the web
4
Web Services vs. Web Apps
Web application Provides service directly to user Web service or (Web API) Provides service to other programs browser web server HTTP web server (service provider) app (service user) HTTP
5
Web Service Protocols Simple Object Access Protocol (SOAP)
Service requests and responses are always done via XML messages, called SOAP envelope Formally supported by World Wide Web Consortium (W3C) Representational State Transfer (REST) Service requests are done via generic HTTP commands: GET, POST, PUT, DELETE Simpler set of operations
6
Other Web Service Protocols
Web feeds RSS Atom Remote procedure call JSON-RPC XML-RPC JavaScript
7
Sample SOAP Message E.g., message requesting IBM stock price
POST /InStock HTTP/1.1 Host: Content-Type: application/soap+xml; charset=utf-8 Content-Length: 299 <?xml version="1.0"?> <soap:Envelope xmlns:soap=" <soap:Header> </soap:Header> <soap:Body> <m:GetStockPrice xmlns:m=" <m:StockName>IBM</m:StockName> </m:GetStockPrice> </soap:Body> </soap:Envelope> HTTP Header SOAP Envelope Desired operation (Verb) Object of interest (Noun)
8
Sample REST Request E.g., message requesting IBM stock price
The above corresponds to the URL GET /stock/ibm HTTP/1.1 Host: HTTP Header Desired operation (Verb) Object of interest (Noun)
9
Data Interchange Formats
XML – eXtensible Markup Language E.g., RSS, Atom Large collection of libraries for processing XML <?xml version="1.0" encoding="ISO "?> <rdf:RDF xmlns:rdf=" xmlns=" <title>Slashdot</title> <link> <description>News for nerds, stuff that matters</description> <dc:subject>Technology</dc:subject> <items> <rdf:Seq> <rdf:li rdf:resource=" /> </ref:Seq> </items> </rdf:RDF>
10
Data Interchange Formats
JSON – JavaScript Object Notation Can be directly evaluated in JavaScript Typically smaller than XML Libraries for other languages are also available { "Person": "firstName": "John", "lastName": "Smith", "age": 25, "Address": "streetAddress":"21 2nd Street", "city":"New York", "state":"NY", "postalCode":"10021" }, "PhoneNumbers": "home":" ", "fax":" " } <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> <PhoneNumbers> <home> </home> <fax> </fax> </PhoneNumbers> </Person> XML JSON
11
Example –Wikipedia RESTful API reference Example
Example
12
Example – HostIP.info RESTful
Determines geographical location of the specified IP address API documentation Example
13
Coding Example E.g., accessing HostIP.info from Python import sys
import json from urllib import urlencode from urllib2 import urlopen response = urlopen(' + urlencode({ 'ip' : sys.argv[1], })) data = json.loads(response.read()) print 'IP Address: %s' % data['ip'] print 'City: %s' % data['city'] print 'Country: %s' % data['country_name']
14
Mashups A mashup is a webpage or application that offers new services by combining data or functionality from two or more sources Main characteristics of mashups Combination Visualization Aggregation They aim to make existing data more useful Example: Wikipediavision Google Maps + Wikipedia
15
More Resources Search engine for web APIs and mashups
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.