Programming for Web Services, Service Oriented Architecture(SOA): SOAP vs. REST Lia Qu April 9th, 2013 1
Table of Content Web Service SOAP REST CityStory - A web service portal Programming Example - US Census Bureau 2
Why Web Services is so important? 3
Why Web Services is so important? Reason 1: Reusing functionality of already developed system in new softwares Reason 2: Facilitates the development of heterogeneous distributed applications Reason 3: Accessibility of applications through firewalls using web protocols. 3
4
Call function()... function1() function2()... 4
Web Service is a way of establishing communication between two softwares Call function()... Client(Service Consumer) Server(Service Provider) function1() function2()... 4
Web Service Communication Condition Call function()... Client(Service Consumer) Server(Service Provider) 5
Web Service Communication Condition Call function()... Client(Service Consumer) Server(Service Provider) Don t need Do not need to use the same programming language Do no need be on the same machine 5
Web Service Communication Condition Call function()... Client(Service Consumer) Don t need Do not need to use the same programming language Do no need be on the same machine Server(Service Provider) Need Must have network connect to these two softwares (Internet using HTTP) Must follow format of I/O messages (SOAP) 5
Simple Object Access Protocol (SOAP) Call function()... Address & Description Client(Service Consumer) Server(Service Provider) 6
Simple Object Access Protocol (SOAP) Call function()... Address & Description Client(Service Consumer) Server(Service Provider) XML(WSDL) Functions this web services offer Signature of each function Standard and protocols used by this web service 6
How to locate XML(WSDL) on Internet? Client(Service Consumer) Server(Service Provider) 7
How to locate XML(WSDL) on Internet? 1. XML(WSDL) Client(Service Consumer) Server(Service Provider) 7
How to locate XML(WSDL) on Internet? 1. XML(WSDL) Access web service Client(Service Consumer) Server(Service Provider) 7
How to locate XML(WSDL) on Internet? Client(Service Consumer) Server(Service Provider) 8
How to locate XML(WSDL) on Internet? Client(Service Consumer) Server(Service Provider) 2. XML(WSDL) UDDI 8
How to locate XML(WSDL) on Internet? Client(Service Consumer) Server(Service Provider) 2. XML(WSDL) UDDI 8
How to locate XML(WSDL) on Internet? Access web service Client(Service Consumer) Server(Service Provider) 2. XML(WSDL) UDDI 8
Representational State Transfer(REST) REST is an architectural style. Any software adhering with the definition of REST would be considered as REST based. RESTful Web Services are the one that supports REST concept. 9
RESTful Web Service Client RESTful Server 10
RESTful Web Service Client RESTful Server Resource... (in format of HTML, XML, JSON, image.etc) 10
RESTful Web Service send a request via URIs Client RESTful Server Resource... (in format of HTML, XML, JSON, image.etc) 10
RESTful Web Service send a request via URIs response = representation of resource Client RESTful Server Resource... (in format of HTML, XML, JSON, image.etc) 10
HTTP is a stateless communication protocol, which best describes RESTful web service send a request via URI Client RESTful Server 11
HTTP is a stateless communication protocol, which best describes RESTful web service send a request via URI Client RESTful Server Uniform interface: GET: retrieve a resource POST: create a resource PUT: update a resource DELETE: delete a resource 11
SOAP vs REST SOAP REST Definition protocol architecture style Service provided function() resources The way to access service Interface Security XML(WSDL) No uniform operation require contextual information, and communication stated URI (URL, URN) Http (GET, POST...) stateless; used in the presence of firewall 12
Use SOAP or REST? 13
Use SOAP or REST? A formal contract must be established to describe the interface that the web service offer. The architecture must address complex nonfunctional requirements that go beyond simple CRUD operations and require contextual information and conversational state to be maintained. The application need to handle asynchronous processing and invocation? The bandwidth issue is particular important? Easy aggregation and deployment to existing application are important to you? 13
Use SOAP or REST? A formal contract must be established to describe the interface that the web service offer. The architecture must address complex nonfunctional requirements that go beyond simple CRUD operations and require contextual information and conversational state to be maintained. (SOAP) The application need to handle asynchronous processing and invocation? (SOAP) (SOAP) The bandwidth issue is particular important? (REST) Easy aggregation and deployment to existing application are important to you? (REST) 13
14
CityStory http://citystory.herokuapp.com 14
Example - US Census Bureau APIs 15
Example - US Census Bureau APIs 16
Example - US Census Bureau APIs Required parameter: - statecode - citycode - population data 16
Example - US Census Bureau APIs Step by Step guide: 1. Request a Key 2. Access a resource through a URL 3. Query response as a JSON array 4. Organize response in Java 5. Visualize it by Google Chart APIs Required parameter: - statecode - citycode - population data 16
Example - US Census Bureau APIs 1. Request a Key (Example of the request URL for 2010 Census SF1 data that has an assigned key inserted.) 17
Example - US Census Bureau APIs 2. Accessing data through URL Type URL in browser s address: http://api.census.gov/data/2010/sf1? key=24c30d6fdf727e050333f2a5f9f6a864a2ff 7b4a&get=NAME&for=state:* 18
Example - US Census Bureau APIs 3. Connect to web service 19
Example - US Census Bureau APIs 4. Query response as a JSON array 20
Example - US Census Bureau APIs 4. Query response as a JSON array statecode citycode 20
Example - US Census Bureau APIs 4. Query response as a JSON array statecode citycode population data... 20
Example - US Census Bureau APIs 21
Example - US Census Bureau APIs - get population of a city. Group the population data by Sex and Age. 22
Example - US Census Bureau APIs - get population of a city. Group the population data by Sex and Age. In Controller: 23
Example - US Census Bureau APIs 5. Visualize it by Google Chart APIs Check the JSON format at: http://citystory.herokuapp.com/population/pennsylvania/pittsburgh 24
Questions? Thank you! 25