Web services CSCI 470: Web Science Keith Vertanen Copyright 2011

Similar documents
Data formats. { "firstname": "John", "lastname" : "Smith", "age" : 25, "address" : { "streetaddress": "21 2nd Street",

Web services CSCI 470: Web Science Keith Vertanen Copyright 2013

Web services CSCI 470: Web Science Keith Vertanen Copyright 2014

Web services. CSCI 470: Web Science Keith Vertanen

XML (Extensible Markup Language)

markup language carry data define your own tags self-descriptive W3C Recommendation

Bioinforma)cs Resources XML / Web Access

11. EXTENSIBLE MARKUP LANGUAGE (XML)

XML extensible Markup Language

Software Engineering Methods, XML extensible Markup Language. Tutorial Outline. An Example File: Note.xml XML 1

INTERNET PROGRAMMING XML

Extensible Markup Language (XML) Hamid Zarrabi-Zadeh Web Programming Fall 2013

Extensible Markup Language (XML) What is XML? Structure of an XML document. CSE 190 M (Web Programming), Spring 2007 University of Washington

Web Programming Paper Solution (Chapter wise)

XML: a "skeleton" for creating markup languages you already know it! <element attribute="value">content</element> languages written in XML specify:

XML CSC 443: Web Programming

The components of a basic XML system.

User Interaction: XML and JSON

User Interaction: XML and JSON

EXtensible Markup Language XML

INTERNET & WEB APPLICATION DEVELOPMENT SWE 444. Fall Semester (081) Module 4 (VII): XML DOM

Extensible Markup Language (XML) What is XML? An example XML file. CSE 190 M (Web Programming), Spring 2008 University of Washington

Web Computing. Revision Notes

Introduction to XML. M2 MIA, Grenoble Université. François Faure

What is XML? XML is designed to transport and store data.

Web Programming Step by Step

JSON. Dr. Kanda Runapongsa Saikaew Computer Engineering Department

Java EE 7: Back-end Server Application Development 4-2

XML for Android Developers. partially adapted from XML Tutorial by W3Schools

EXtensible Markup Language XML

but XML goes far beyond HTML: it describes data

AJAX ASYNCHRONOUS JAVASCRIPT AND XML. Laura Farinetti - DAUIN

The <schema> Element. <?xml version="1.0"?> <xs:schema>... </xs:schema>

Web Programming Pre-01A Web Programming Technologies. Aryo Pinandito, ST, M.MT

XML Processing & Web Services. Husni Husni.trunojoyo.ac.id

CSE 154 LECTURE 23: XML

E-Applications. XML and DOM in Javascript. Michail Lampis

Introduction Syntax and Usage XML Databases Java Tutorial XML. November 5, 2008 XML

JSON is a light-weight alternative to XML for data-interchange JSON = JavaScript Object Notation

MANAGING INFORMATION (CSCU9T4) LECTURE 2: XML STRUCTURE

Web Services Part I. XML Web Services. Instructor: Dr. Wei Ding Fall 2009

CSC Web Technologies, Spring Web Data Exchange Formats

XML. Presented by : Guerreiro João Thanh Truong Cong

ASP.NET AJAX adds Asynchronous JavaScript and XML. ASP.NET AJAX was up until the fall of 2006 was known by the code-known of Atlas.

W3C XML XML Overview

/ Introduction to XML

CSCI 136: Fundamentals of Computer Science II Keith Vertanen Copyright 2012

Languages of the WEB. Jukka K. Nurminen

Introduction to Web Services

EAE-2037 Loading transactions into your EAE/ABSuite system. Unite 2012 Mike Bardell

XML. Miroslav Trajanović. Šta je XML

JSON as an XML Alternative. JSON is a light-weight alternative to XML for datainterchange

Session 23 XML. XML Reading and Reference. Reading. Reference: Session 23 XML. Robert Kelly, 2018

XML JavaScript Object Notation JSON Cookies Miscellaneous What Javascript can t do. OOP Concepts of JS

COMP9321 Web Application Engineering. Extensible Markup Language (XML)

From (Copyright Refsnes Data) XML stands for EXtensible Markup Language.

CSC System Development with Java Working with XML

REST. Web-based APIs

Introduction to XML. An Example XML Document. The following is a very simple XML document.

INFO/CS 4302 Web Informa6on Systems

XML stands for Extensible Markup Language and is a text-based markup language derived from Standard Generalized Markup Language (SGML).

Semantic Web. XML and XML Schema. Morteza Amini. Sharif University of Technology Fall 94-95

AJAX: Rich Internet Applications

AJAX. Lab. de Bases de Dados e Aplicações Web MIEIC, FEUP 2010/11. Sérgio Nunes

XML Structures. Web Programming. Uta Priss ZELL, Ostfalia University. XML Introduction Syntax: well-formed Semantics: validity Issues

A) XML Separates Data from HTML

XML. Marie Dubremetz Uppsala, April 2014

16. Objects & JSON. Dr. Dave Parker. Informa;on and the Web, 2014/15

CSI 3140 WWW Structures, Techniques and Standards. Representing Web Data: XML

Copyright 2014 Blue Net Corporation. All rights reserved

Data Presentation and Markup Languages

,

B4M36DS2, BE4M36DS2: Database Systems 2

XMLHttpRequest. CS144: Web Applications

CITS1231 Web Technologies. Ajax and Web 2.0 Turning clunky website into interactive mashups

COMP9321 Web Application Engineering

2/6/2012. Rich Internet Applications. What is Ajax? Defining AJAX. Asynchronous JavaScript and XML Term coined in 2005 by Jesse James Garrett


XML (Extensible Markup Language

languages for describing grammar and vocabularies of other languages element: data surrounded by markup that describes it

UNIT-II : VIRTUALIZATION & COMMON STANDARDS IN CLOUD COMPUTING

XML: some structural principles

AJAX and PHP AJAX. Christian Wenz,

NATIONAL DIPLOMA IN COMPUT TER TECHNOLOGY

What is a web site? Web editors Introduction to HTML (Hyper Text Markup Language)

External data representation

Alternative Data Models Toward NoSQL

Delivery Options: Attend face-to-face in the classroom or remote-live attendance.

Client-side Web Engineering 2 From XML to Client-side Mashups. SWE 642, Spring 2008 Nick Duan. February 6, What is XML?

The main Topics in this lecture are:

Delivery Options: Attend face-to-face in the classroom or via remote-live attendance.

Module 1-XML 1 INTRODUCTION. Browser s/w (Mozilla, IE, Netscape, etc)

CS109 Data Science Data Munging

Web Services. Richard Sinnott.

Ajax. Ronald J. Glotzbach

University College of Southeast Norway. Web Services. with Examples. Hans-Petter Halvorsen,

CT51 WEB TECHNOLOGY ALCCS-FEB 2014

Lesson 12: JavaScript and AJAX

TagSoup: A SAX parser in Java for nasty, ugly HTML. John Cowan

XML. Jonathan Geisler. April 18, 2008

Transcription:

Web services CSCI 470: Web Science Keith Vertanen Copyright 2011

Web services What does that mean? Why are they useful? Examples! Major interac>on types REST SOAP Data formats: XML JSON Overview 2

3

W3C says 1.4 What is a Web service? For the purpose of this Working Group and this architecture, and without prejudice toward other definitions, we will use the following definition: [Definition: A Web service is a software system designed to support interoperable machine-to-machine interaction over a network. It has an interface described in a machine-processable format (specifically WSDL). Other systems interact with the Web service in a manner prescribed by its description using SOAP messages, typically conveyed using HTTP with an XML serialization in conjunction with other Web-related standards.] 4

Web services Basic idea: Allows others to make use of your: Unique func>onality, e.g. transla>ng English to Spanish Unique data, e.g. find out where your FedEx package is Do this over the Internet In a standard way using a known protocol (e.g. HTTP) Possible business uses: Within a company to integrate things Between a company and partners For free, promote your new fangled search engine (e.g. Bing) For money, (e.g. $5/1000 search queries) 5

Bing web services 6

Using Bing search API Apply for an app ID Get a Windows Live account e.g. ABDJ3983HEFHB39398FEFE37 Choose your "protocol": JavaScript Object Nota>on (JSON) Extensible Markup Language (XML) SOAP (original Simple Object Access Protocol) Make your search request Using a language/command line tool of your choice My example: REST with JSON result format 7

Using Bing search API Find the top- 10 Bing results for "orediggers" Make a HTTP GET request http://api.bing.net/json.aspx? AppId=AFKJEAWKFJEAWKFJA&Version=2.2& Market=enUS& Query=orediggers&Sources=web+spell& Web.Count=10& JsonType=raw 8

Yahoo web services 9

Google web services 10

11

Facebook web services 12

FedEx web services 13

Twiier web services 14

statuses/sample Sipping on the Twiier Spritzer Returns a random sample of all public statuses. The default access level, Spritzer provides a small proportion of the Firehose, very roughly, 1% of all public statuses. The Gardenhose access level provides a proportion more suitable for data mining and research applications that desire a larger proportion to be statistically significant sample. Currently Gardenhose returns, very roughly, 10% of all public statuses. Note that these proportions are subject to unannounced adjustment as traffic volume varies. URL: https://stream.twitter.com/1/statuses/sample.json Method(s): GET Parameters: count, delimited, stall_warnings Returns: stream of status element Just go to this URL in a browser and enter your Twiier username and password! Or programma>cally: curl -k https://stream.twitter.com/1/statuses/sample.json - umyuser:mypassword 15

Programma>c access static void Main(string[] args) { HttpWebRequest webrequest = null; HttpWebResponse webresponse = null; StreamReader responsestream = null;... while (true) { try { webrequest = (HttpWebRequest) WebRequest.Create("https://stream.twitter.com/1/statuses/sample.json"); webrequest.credentials = new NetworkCredential("username", "password"); webrequest.timeout = - 1; webresponse = (HttpWebResponse) webrequest.getresponse(); responsestream = new StreamReader(webResponse.GetResponseStream(), System.Text.Encoding.GetEncoding("utf- 8")); Console.WriteLine(responseStream.ReadLine()); } catch (WebException ex) { Console.WriteLine(ex.Message); } C# example prin>ng out the Twiier spritzer. 16

Twiier streaming API Streaming API: ~1% of the world's Tweets for free Since early 2011: 115 GB compressed (ibex) 17

I just bought some milk What do with all this Twiier data? Tweets tend to be informal person- to- person like communica>ons Augmenta>ve and Alterna>ve Communica>on (AAC) Enable users with certain disabili>es to par>cipate in everyday conversa>ons AAC devices ooen rely on sta>s>cal language models Language models historically have been trained poorly on non- representa>ve data 18

19

20

Mashups A web applica>on hybrid Mashups Combine the func>onality or data from several web sites Frequently done using web services e.g. Combine Google Maps API with Twiier API to show 21

Web services protocols Two major protocols: REST (Representa>onal state transfer) An HTTP GET request to a specific URL HTTP is the protocol, no other choice e.g. my Bing and Twiier examples SOAP Originally Simple Object Access Protocol Dropped acronym, not so simple? XML message format Really a framework for specifying protocols HTTP is one profile choice Strong typing Generate proxy class using toolkit 22

Bing via SOAP 23

using BingSOAP.net.bing.api; namespace BingSOAP { class Program { static void Main(string[] args) { BingService service = new BingService(); SearchRequest request = new SearchRequest(); request.appid = "FAEWKJAEAEFJKAFWJKJAEFKJEFWKAFEWJKAWEFKAFWEJFAWE"; request.sources = new SourceType[] { SourceType.Web }; request.query = "orediggers"; } } } SearchResponse response = service.search(request); int i = 0; foreach (WebResult r in response.web.results) { Console.WriteLine(i + ": " + r.title); Console.WriteLine(i + ": " + r.url); Console.WriteLine(i + ": " + r.description); Console.WriteLine(); i++; } C# example that does a query using the Bing SOAP API. 24

25

26

Data format: XML XML (Extensible Markup Language) Human readable W3C recommenda>on Markup language like HTML Originally a document format Microsoo Office (Office Open XML) OpenOffice (OpenDocument) Apple iwork Can be used for data interchange e.g. SOAP, RSS, Atom 27

XML root element (required) child elements <?xml version="1.0" encoding="iso-8859-1"?> <note> <to>tove</to> <from>jani</from> <heading>reminder</heading> <body>don't forget me this weekend!</body> </note> Every tag must be closed <b><i>this text is bold and italic</b></i> Example of improperly nested HTML <b><i>this text is bold and italic</i></b> Properly nested XHTML 28

<bookstore> <book category="cooking"> <title lang="en">everyday Italian</title> <author>giada De Laurentiis</author> <year>2005</year> <price>30.00</price> </book> <book category="children"> <title lang="en">harry Potter</title> <author>j K. Rowling</author> <year>2005</year> <price>29.99</price> </book> <book category="web"> <title lang="en">learning XML</title> <author>erik T. Ray</author> <year>2003</year> <price>39.95</price> </book> <!-- This is a comment --> </bookstore> Tags are case- sensi>ve, <>tle>!= <Title> Aiributes must be quoted A comment in the XML document 29

<p>this is a paragraph. <br> Unclosed tags in an HTML document. <p>this is a paragraph.</p> <br /> In XHTML, every tag must be closed. Whitespace is preserved <message>if salary < 1000 then</message> Special characters need to be escaped. < < less than > > greater than & & ampersand &apos; ' apostrophe " " quotation mark 30

<note date="10/01/2008"> <to>tove</to> <from>jani</from> <heading>reminder</heading> <body>don't forget me this weekend!</body> </note> <note> <date>10/01/2008</date> <to>tove</to> <from>jani</from> <heading>reminder</heading> <body>don't forget me this weekend!</body> </note> <note> <date> <day>10</day> <month>01</month> <year>2008</year> </date> <to>tove</to> <from>jani</from> <heading>reminder</heading> <body>don't forget me this weekend!</body> </note> 31

Valida>ng XML Method 1: Document Type Defini>on (DTD) <?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE note SYSTEM "Note.dtd"> <note> <to>tove</to> <from>jani</from> <heading>reminder</heading> <body>don't forget me this weekend!</body> </note> <!DOCTYPE note [ <!ELEMENT note (to,from,heading,body)> <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT heading (#PCDATA)> <!ELEMENT body (#PCDATA)> ]> 32

Valida>ng XML Method 2: XML Schema XSD (XML Schema Defin>on) <xs:element name="note"> <xs:complextype> <xs:sequence> <xs:element name="to" type="xs:string"/> <xs:element name="from" type="xs:string"/> <xs:element name="heading" type="xs:string"/> <xs:element name="body" </xs:sequence> </xs:complextype> </xs:element> type="xs:string"/> 33

Parsing XML XML DOM (Document Object Model) Expressing and interac>ng with XML data Modern browsers/languages have a built- in DOM parser libxml2 Bindings for C++, C#, Python, PHP, Perl, MSXML Microsoo XML Core Services Or, just use simple string parsing Find stuff between start and end tag Probably naughty but fast 34

<html><body><h1>w3schools Internal Note</h1> <div> <b>to:</b> <span id="to"></span><br /> <b>from:</b> <span id="from"></span><br /> <b>message:</b> <span id="message"></span> </div> <script type="text/javascript"> if (window.xmlhttprequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp = new XMLHttpRequest(); } else { // code for IE6, IE5 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.open("get","note.xml",false); xmlhttp.send(); xmldoc = xmlhttp.responsexml; document.getelementbyid("to").innerhtml = xmldoc.getelementsbytagname("to")[0].childnodes[0].nodevalue; document.getelementbyid("from").innerhtml = xmldoc.getelementsbytagname("from")[0].childnodes[0].nodevalue; document.getelementbyid("message").innerhtml = xmldoc.getelementsbytagname("body")[0].childnodes[0].nodevalue; </script> </body></html> 35

Data format: JSON JSON (JavaScript Object Nota>on), "Jason" 2001 Popularized by Doug Crockford, Yahoo hip://youtu.be/- C- JoyNuQJs Lightweight alterna>ve to XML Spec fits on the back of a business card Human readable Derived from how JavaScript represents data structures and associa>ve arrays Language independent data interchange {to:"session", do:"test", text:"hello world"} The world's first JSON message. Failed due to JavaScript reserved word "do". Decided to always force quo>ng of key. 36

JSON example { } "firstname": "John", "lastname" : "Smith", "age" : 25, "address" : { "streetaddress": "21 2nd Street", "city" : "New York", "state" : "NY", "postalcode" : "10021" }, "phonenumber": [ { "type" : "home", "number": "212 555-1234" }, { "type" : "fax", "number": "646 555-4567" } ] 37

JSON's grammar 38

39

Parsing JSON In JavaScript JSON is subset of the literal JavaScript nota>on var myjsonobject = {"bindings": [ {"ircevent": "PRIVMSG", "method": "newuri", "regex": "^http://.*"}, {"ircevent": "PRIVMSG", "method": "deleteuri", "regex": "^delete.*"}, {"ircevent": "PRIVMSG", "method": "randomuri", "regex": "^random.*"} ] }; myjsonobject.bindings[0].method // "newuri" 40

Parsing JSON In Java Freely available parsing class 41

Summary Web services Access to remote procedures / data Promotes integra>on Beier than everybody inven>ng custom interchange schemes Makes it through firewalls Runs on top of the mature web architecture Common data formats: XML JSON Possible paper / presenta>on topics: Analysis of differences between SOAP and REST Learn details and do something interes>ng with a specific API e.g. What can be done with the Facebook API? 42