1 / 15

Introduction to Web Services

Introduction to Web Services. Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th http://www.cpe.ku.ac.th/~cpj Computer Engineering Department Kasetsart University, Bangkok, Thailand. Traditional World-Wide-Web. Designed for human-to-app interactions Information sharing

madison
Download Presentation

Introduction to Web Services

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to Web Services Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th http://www.cpe.ku.ac.th/~cpj 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: www.example.org Content-Type: application/soap+xml; charset=utf-8 Content-Length: 299 <?xml version="1.0"?> <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"> <soap:Header> </soap:Header> <soap:Body> <m:GetStockPrice xmlns:m="http://www.example.org/stock"> <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: www.example.org HTTP Header Desired operation(Verb) Object of interest(Noun) http://www.example.org/stock/ibm

  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-8859-1"?> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://purl.org/rss/1.0/"> <title>Slashdot</title> <link>http://slashdot.org/</link> <description>News for nerds, stuff that matters</description> <dc:subject>Technology</dc:subject> <items> <rdf:Seq> <rdf:li rdf:resource="http://it.slashdot.org/story/11/02/14/0337211/Recent-HP-Laptops-Shipped-CPU-Choking-Wi-Fi-Driver?from=rss" /> </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":"212 555-1234", "fax":"646 555-4567" } } } <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>212 555-1234</home> <fax>646 555-4567</fax> </PhoneNumbers> </Person> XML JSON

  11. Example –Wikipedia • RESTful • API reference • http://en.wikipedia.org/w/api.php • Example • http://en.wikipedia.org/w/api.php?format=json&action=query&titles=Kasetsart%20University&prop=revisions&rvprop=content

  12. Example – HostIP.info • RESTful • Determines geographical location of the specified IP address • API documentation • http://www.hostip.info/use.html • Example • http://api.hostip.info/get_json.php?ip=158.108.2.71

  13. Coding Example • E.g., accessing HostIP.info from Python import sys import json from urllib import urlencode from urllib2 import urlopen response = urlopen('http://api.hostip.info/get_json.php?' + 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 • http://www.lkozma.net/wpv/index.html

  15. More Resources • Search engine for web APIs and mashups • http://www.programmableweb.com

More Related