introduction to web apis and protocols by j. h. wang dec. 12, 2011

31
Introduction to Web APIs and Protocols By J. H. Wang Dec. 12, 2011

Upload: alexandra-wilkerson

Post on 13-Jan-2016

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Introduction to Web APIs and Protocols By J. H. Wang Dec. 12, 2011

Introduction to Web APIs and Protocols

By J. H. WangDec. 12, 2011

Page 2: Introduction to Web APIs and Protocols By J. H. Wang Dec. 12, 2011

Outline

• Popular Web APIs– Google APIs– Yahoo! APIs– Bing API– Others

• Protocols in Web APIs– HTTP– HTML– JSON– XML

Page 3: Introduction to Web APIs and Protocols By J. H. Wang Dec. 12, 2011

Google APIs

• Google APIs (http://code.google.com/intl/zh-TW/more/ )– AJAX APIs (deprecated)

• AJAX Search: Blog, Book, News, Web, Image, Video

– Custom Search API– Maps API– Google Code Playground

• http://code.google.com/apis/ajax/playground/

Page 4: Introduction to Web APIs and Protocols By J. H. Wang Dec. 12, 2011

• Others:– Google Chart API (Visualization API), Desktop API, Calendar

API, Contacts API, Picasa API, Social Graph API, Earth API, GeoCoding API, Prediction API, URL Shortener API, YouTube API

– Google Data API• Book Data, Calendar Data, Contacts Data, Web Albums Data,

Spreadsheets Data, YouTube Data, …– University Research Program for Google Search and

Translate (not accepting new applications)– Google API consoles: translate API, prediction API, custom

search API• Check more at: Google Code and Google Labs (more

information in English version)

Page 5: Introduction to Web APIs and Protocols By J. H. Wang Dec. 12, 2011

Yahoo! APIs

• Yahoo! APIs (http://developer.yahoo.com/)• Search

– BOSS (Build your Own Search Service) (not free!)• Web, image, news, blogs (beta)

– SearchMonkey: to enhance search results (shut down in Oct. 2010)

– Search Marketing• Location

– Local, Maps– PlaceFinder, PlaceMaker– Traffic, Weather

Page 6: Introduction to Web APIs and Protocols By J. H. Wang Dec. 12, 2011

• Others– Yahoo Social APIs: social directory, contacts, user status,

updates– Media: Flickr API, music, media player– GeoPlanet, Network Time, Term Extraction, Yahoo!

Answers – Taiwan ONLY: 生活 +, 地圖 , 知識 +, 斷章取義 , 無名小

站 , 奇摩拍賣• Check more at: Yahoo! Developer Network (YDN) (

http://developer.yahoo.com/ )

Page 7: Introduction to Web APIs and Protocols By J. H. Wang Dec. 12, 2011

Bing APIs

• Bing API 2.0: (http://www.bing.com/toolbox/bingdeveloper/ )– Web, image, news, video search– Translation, spell, relatedsearch

• Bing Maps– AJAX control, iOS control, SOAP services, REST services

• Others– More information at: Bing Developer Center

Page 8: Introduction to Web APIs and Protocols By J. H. Wang Dec. 12, 2011

Others

• Facebook API (https://developers.facebook.com/ )• micro-blogging

– Twitter API (https://dev.twitter.com/ )– plurk API (http://www.plurk.com/API )– Digg API (http://developers.digg.com/ )

• Technorati API: blog search (terminated in Oct. 2009!)

• MySpace API (http://developer.myspace.com/ )• Del.icio.us API (http://delicious.com/help/api )

– social bookmarks

Page 9: Introduction to Web APIs and Protocols By J. H. Wang Dec. 12, 2011

• New York Times API (http://developer.nytimes.com )– Article search– Movie reviews– TimesTags– …

• Scopus API (http://searchapi.scopus.com/ )– search for papers, authors, affiliation, citations

• MediaWiki API• Ebay API

Page 10: Introduction to Web APIs and Protocols By J. H. Wang Dec. 12, 2011

Mashups (Web Application Hybrid)

• Using and combing data, presentation, or functionality from two or more sources to create new services

• Using open APIs and data sources to produce enriched results

Page 11: Introduction to Web APIs and Protocols By J. H. Wang Dec. 12, 2011

Some Example Mashups

• HousingMaps– http://www.housingmaps.com/

• ChicagoCrime– http://www.chicagocrime.org/

Page 12: Introduction to Web APIs and Protocols By J. H. Wang Dec. 12, 2011

Example: Tourist Blog Information Integration System

Page 13: Introduction to Web APIs and Protocols By J. H. Wang Dec. 12, 2011

System Architecture

Wordsegmentation

Wordsegmentation

YouTube

location

others

Resultpresentation

Resultpresentation

Google Maps

Tourist blogs

blogs

query

Panoramio

Wikipedia

Page 14: Introduction to Web APIs and Protocols By J. H. Wang Dec. 12, 2011

Some Factors in Integrating Web APIs

• What service are you going to provide?– Location-based services: Geo & Local APIs– Data sources: Web, news, blog, or personal data?– Social relationships?– Visualization?

• Which platform?– Mobile devices– PCs

• Data quality?

Page 15: Introduction to Web APIs and Protocols By J. H. Wang Dec. 12, 2011

Some Protocols in Web Services

• RESTful (REpresentational State Transfer)• SOAP (Simple Object Access Protocol)

– The standard, version 1.2

• HTTP • JSON (JavaScript Object Notation)• XML

Page 16: Introduction to Web APIs and Protocols By J. H. Wang Dec. 12, 2011

SOAP vs. REST

• SOAP– Pros:

• Language, platform, and transport agnostic• Designed to handle distributed computing environments• The standard for Web services, and has better support from other

standards (WSDL, WS-*)• Built-in error-handling• Extensibility

– Cons:• Conceptually more difficult, more heavy-weight• More verbose• Harder to develop, requires tools

Page 17: Introduction to Web APIs and Protocols By J. H. Wang Dec. 12, 2011

• REST– Pros:

• Language and platform agnostic• Much simpler to develop than SOAP• Small learning curve• Concise, no need for additional messaging layer• Closer in design and philosophy to the Web

– Cons:• Assumes a point-to-point communication model• Lack of standards support for security, policy, reliable messaging• Tied to the HTTP transport

Page 18: Introduction to Web APIs and Protocols By J. H. Wang Dec. 12, 2011

HTTP

• HyperText Transfer Protocol– The protocol standard for the World Wide Web– Defined by IETF, W3C– RFC 2616, HTTP 1.1

• Overview– Web browser (the HTTP client) submits an HTTP

request to the HTTP server, which provides resources (such as HTML files) and returns a response

Page 19: Introduction to Web APIs and Protocols By J. H. Wang Dec. 12, 2011

HTTP Request Message

• Request line: – GET /images/logo.png HTTP/1.1

• Headers – Accept-Language: en

• Empty line• (Each line must end with <CR><LF>)• Optional message body

Page 20: Introduction to Web APIs and Protocols By J. H. Wang Dec. 12, 2011

Request Methods

• 9 methods indicating the action to be performed on the identified resource– GET– POST– PUT– DELETE– HEAD, TRACE, OPTIONS, CONNECT, PATCH

Page 21: Introduction to Web APIs and Protocols By J. H. Wang Dec. 12, 2011

Some HTTP Header Fields• Requests

– Accept-Charset– Connection– Content-Type– Content-Length– Date– From – Host

• Responses– Connection– Content-Type– Content-Length– Date

Page 22: Introduction to Web APIs and Protocols By J. H. Wang Dec. 12, 2011

Response Message

• Status line– Status codes

• 404– Reason phrase

• Not found

• Types of status codes– 1xx informational– 2xx success– 3xx redirection– 4xx client error– 5xx server error

Page 23: Introduction to Web APIs and Protocols By J. H. Wang Dec. 12, 2011

Example HTTP Session• Client request

– GET /index.html HTTP/1.1<CR><LF>– Host: www.example.com<CR><LF>– <CR><LF>

• Server response– HTTP/1.1 200 OK– Date: Mon, 23 May 2005 22:38:34 GMT– Server: Apache/1.3.3.7 (Unix) (Red-Hat/Linux)– Last-Modified: Wed, 08 Jan 2003 23:11:55 GMT– Etag: “3f80f-1b6-3e1cb03b”– Accept-Ranges: bytes– Content-Length: 438– Connection: close– Content-Type: text/html; charset=UTF-8

Page 24: Introduction to Web APIs and Protocols By J. H. Wang Dec. 12, 2011

HTML

• HyperText Markup Language: the language for Web pages– HTML 4.01 (W3C recommendation, 1999)– HTML 5 (W3C working draft, May 2011)

• Elements– Tags: <xxx> … </xxx> – Attributes – Ex: headings, paragraphs, tables, forms,

comments, …

Page 25: Introduction to Web APIs and Protocols By J. H. Wang Dec. 12, 2011

An Example HTML File

• <html> <head> <title>Hello HTML</title> </head> <body> <p>Hello World!</p> </body> </html>

Page 26: Introduction to Web APIs and Protocols By J. H. Wang Dec. 12, 2011

JSON

• JavaScript Object Notation (JSON): a lightweight data-interchange format (http://www.json.org/ )– Easy for humans to read and write– Easy for machines to parse and generate– Based on a subset of JavaScript Programming Language,

but it’s completely language independent• JSON is built on two structures

– Name/value pairs: objects– Ordered list of values: arrays

• More details in RFC 4627

Page 27: Introduction to Web APIs and Protocols By J. H. Wang Dec. 12, 2011

JSON Examples

• { "Image": { "Width": 800, "Height": 600, "Title": "View from 15th Floor", "Thumbnail": {"Url":"http://www.example.com/image/481989943", "Height": 125, "Width": "100" }, "IDs": [116, 943, 234, 38793] } }

Page 28: Introduction to Web APIs and Protocols By J. H. Wang Dec. 12, 2011

JSON Examples

• [ { "precision": "zip", "Latitude": 37.7668, "Longitude": -122.3959, "Address": "", "City": "SAN FRANCISCO", "State": "CA", "Zip": "94107", "Country": "US" }, { "precision": "zip", "Latitude": 37.371991, "Longitude": -122.026020, "Address": "", "City": "SUNNYVALE", "State": "CA", "Zip": "94085", "Country": "US" } ]

Page 29: Introduction to Web APIs and Protocols By J. H. Wang Dec. 12, 2011

XML

• eXtensible Markup Language: a set of rules for encoding documents in machine-readable form– XML 1.0 (W3C Recommendation)– An application profile of SGML (ISO 8879)

Page 30: Introduction to Web APIs and Protocols By J. H. Wang Dec. 12, 2011

An Example XML File

• <?xml version="1.0"?><note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body></note>

Page 31: Introduction to Web APIs and Protocols By J. H. Wang Dec. 12, 2011

Thanks for Your Attention!