Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Web Services and Web API’s Richard Holowczak Baruch College December, 2014.

Similar presentations


Presentation on theme: "Introduction to Web Services and Web API’s Richard Holowczak Baruch College December, 2014."— Presentation transcript:

1 Introduction to Web Services and Web API’s Richard Holowczak Baruch College December, 2014

2 Evolution of Web Services Each web site creates custom scripts and web application programs to handle all business logic Over time, some patterns emerge: Query a catalog of items Add items to a shopping cart Calculate shipping methods and costs Calculate taxes Generate a Configuration Generate a Quotation Approve payment Generate a Receipt Handle support questions Etc. Creating custom solutions for each business is costly

3 Distributed Systems: Variations on an old theme Examples of “tightly-coupled” services: Remote procedure call (RPC) Common Object Request Broker (CORBA) Distributed Component Object Model (DCOM) Systems are “brittle” in that often trivial changes to a service can break the whole system Difficult to inter-operate across operating systems and hardware platforms Network security issues

4 Standardizing Web Services - Requirements Advertising available Web Services Searching for Web Services Calling a Web Service Handling Web service Responses All done using “web” protocols (e.g., over standard network ports) Service – Oriented Architecture (SOA)

5 Web Service Description Language (WSDL) Describes the capabilities of a web service including: Where the web service is located (URL) What input parameters the web service requires What operations (calculations, queries, etc.) the web service supports What output the web service generates Written as an XML Document TypesWhat Data Types does the service support (string, number, etc.) MessageThe parts that make up the request and response messages portTypeDescribes the services in terms of the messages and types BindingDefines the service locations for each operation Example: http://www.w3schools.com/webservices/tempconvert.asmx?WSDL Universal Description, Discovery and Integration (UDDI) Used to locate available web services

6 Simple Object Access Protocol (SOAP) Communications protocol used to assemble a distributed SOA application Works in a “machine and OS independent” fashion Uses HTTP as an underlying transport mechanism Request is an XML document Response is an XML document Contains: EnvelopeIndicates what is inside is a SOAP message HeaderIndicates what the receiver must know to process BodyRequest (or Response) information FaultError handling support Example: http://www.w3schools.com/webservices/tempconvert.asmx?op=CelsiusToFahrenheit

7 Example SOAP Message <soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> string Try it: http://www.w3schools.com/webservices/tempconvert.asmx?op=CelsiusToFahrenheit

8 REST Protocol SOA using SOAP, WSDL, etc. has high overhead What about simple requests and responses? REpresentational State Transfer (REST) Request uses HTTP with only 4 operations: GET, POST, PUT, and DELETE Response can be XML, JSON, CSV or plain text Viewed as a “lightweight” alternative to SOAP Example: http://rpc.geocoder.us/service/csv?address=151+E+25th+Street+New+York+NY

9 JSON Documents JavaScript Object Notation (JSON) Easier to parse than XML Very little in the way of “type safety” About as “loosely connected” as you can get Objects have Properties Properties can be single valued: String"name" : "Joe Smith“ Properties can be Sets of values using square brackets "working_on" : ["Project1", "Project2", "Project3" ] Example comparing JSON to XML: http://json.org/example

10 JSON Document Example employee1 = { name: { first: "Joe", last: "Smith" }, birth: new Date('January 5, 1972'), compensation: { salary: Number(48500), bonus: Number(2500) }, department : NumberLong(5), projects: [ "NewBenefits", "Payroll" ] }

11 Web APIs Web Application Programming Interfaces are sets of web services that can be incorporated into web or mobile applications Some free services but most require registration to obtain an “API key” or “API Token” API Documentation will provide the set of methods and acceptable parameters Examples: Google API: https://developers.google.com/apis-explorer/#p/ Facebook API: https://developers.facebook.com/docs/graph-api/ Amazon API: https://developer.amazon.com/public/apis

12 Facebook Web API Facebook Graph API Explorer Tool: https://developers.facebook.com/tools/explorer/

13 Facebook Web API Get an Access token Select Permissions (if necessary, log in to Facebook)

14 Facebook Web API REST Queries Show everything about a user: /826693880709096? Show Everything about a me: /me?

15 Facebook Web API Show only names of schools attended in education: me?fields=education{school{name}}

16 Compare Approaches ClientRequest Protocol ResponseService Web Browser HTTPHTMLApplication Specific Web Service SOAP XML General Purpose Service Web Service RESTXML,JSON, CSV General Purpose Service


Download ppt "Introduction to Web Services and Web API’s Richard Holowczak Baruch College December, 2014."

Similar presentations


Ads by Google