More APIs: Web Services CMPT 281. Announcements Project milestone Lab: – Web services examples.

Slides:



Advertisements
Similar presentations
REST Vs. SOAP.
Advertisements

Introduction to Web Services
Web Service Testing RESTful Web Services Snejina Lazarova Dimo Mitev
What are Web Services? How to use them?
JSON Valery Ivanov.
With jQuery and AJAX Doncho Minkov Telerik Corporation Technical Trainer.
9. AJAX & RIA. 2 Motto: O! call back yesterday, bid time return. — William Shakespeare.
19-Jun-15 Ajax. The hype Ajax (sometimes capitalized as AJAX) stands for Asynchronous JavaScript And XML Ajax is a technique for creating “better, faster,
IST 221 Internet Concepts and Applications Internet, WWW and HTML 1.
Topics in this presentation: The Web and how it works Difference between Web pages and web sites Web browsers and Web servers HTML purpose and structure.
Computer Science 101 Web Access to Databases Overview of Web Access to Databases.
RESTful Web Development With Nodejs and Express. REST Stands for REpresentational State Transfer Has the following constraints: ◦Client-Server ◦Stateless.
IT 210 The Internet & World Wide Web introduction.
Ajax (Asynchronous JavaScript and XML). AJAX  Enable asynchronous communication between a web client and a server.  A client is not blocked when an.
CGI and AJAX CS-260 Dick Steflik.
CSCI 6962: Server-side Design and Programming Introduction to AJAX.
Chapter 16 The World Wide Web Chapter Goals Compare and contrast the Internet and the World Wide Web Describe general Web processing Describe several.
REST.  REST is an acronym standing for Representational State Transfer  A software architecture style for building scalable web services  Typically,
Wyatt Pearsall November  HyperText Transfer Protocol.
The New Zealand Institute for Plant & Food Research Limited Matthew Laurenson Web Services: Introduction & Design Considerations.
ITIS 1210 Introduction to Web-Based Information Systems Chapter 23 How Web Host Servers Work.
Python and REST Kevin Hibma. What is REST? Why REST? REST stands for Representational State Transfer. (It is sometimes spelled "ReST".) It relies on a.
HTML5. HTML5’s overall theme The browser as a rich application platform rich, cross-device user interfaces offline operation capability hardware access.
The Document Object Model. The Web B.D, A.D. They aren’t web pages, they’re document objects A web browser interprets structured information. A server.
Cross Site Integration “mashups” cross site scripting.
1 Welcome to CSC 301 Web Programming Charles Frank.
Web Design (1) Terminology. Coding ‘languages’ (1) HTML - Hypertext Markup Language - describes the content of a web page CSS - Cascading Style Sheets.
Overview Web Session 3 Matakuliah: Web Database Tahun: 2008.
Google Data Protocol Guy Mark Lifshitz. Motivation Google’s Mission: – Organize the world’s information – Make information universally accessible – Provide.
1 Alternative view on Internet Computing Web 1.0 –Web 1.0 is first generation, Web Information based. Driven by Information provider. Web 2.0 Ajax enabled.
Introduction to Web Services
CSCE 315 – Programming Studio Spring Goal: Reuse and Sharing Many times we would like to reuse the same process or data for different purpose Want.
Module: Software Engineering of Web Applications Chapter 2: Technologies 1.
RESTful Web Services What is RESTful?
JSON – Java Script Object Notation. What is JSON JSON is a data interchange format Interactive Web 2.0 applications, no more use page replacement. Data.
Web Technologies Lecture 10 Web services. From W3C – A software system designed to support interoperable machine-to-machine interaction over a network.
AJAX. Ajax  $.get  $.post  $.getJSON  $.ajax  json and xml  Looping over data results, success and error callbacks.
CHAPTER 8 AJAX & JSON WHAT IS AJAX? Ajax lets you…
AJAX and REST. Slide 2 What is AJAX? It’s an acronym for Asynchronous JavaScript and XML Although requests need not be asynchronous It’s not really a.
AJAX Use Cases for WSRP Subbu Allamaraju BEA Systems Inc WSRP F2F Meeting, May 2006.
JavaScript, Sixth Edition Chapter 11 Updating Web Pages with Ajax.
Web Services Essentials. What is a web service? web service: software functionality that can be invoked through the internet using common protocols like.
NCCUCS 軟體工程概論 Lecture 5: Ajax, Mashups April 29, 2014.
JQuery, JSON, AJAX. AJAX: Async JavaScript & XML In traditional Web coding, to get information from a database or a file on the server –make an HTML form.
Embt.co/sprint-rest-json-services Blog Notes: Building RESTful servers. In C++ Builder Developer Skill Sprint Tips, Tricks and Techniques The Ultimate.
National College of Science & Information Technology.
Web Development. Agenda Web History Network Architecture Types of Server The languages of the web Protocols API 2.
Lesson 11: Web Services and API's
4.01 How Web Pages Work.
WEB SERVICES.
AJAX and REST.
Unit – 5 JAVA Web Services
GF and RS, Dept. of CS, Mangalore University
Subbu Allamaraju BEA Systems Inc
Lesson 11: Web Services & API's
Ajax Design Patterns – Programming Practices in Web Services
Session V HTML5 APIs - AJAX & JSON
WEB API.
HTML Level II (CyberAdvantage)
HTML5 AJAX & JSON APIs
Lesson 11: Web Services and API's
MIS JavaScript and API Workshop (Part 3)
Introduction to World Wide Web
Python and REST Kevin Hibma.
Lecture 14: JSON and Web SERVICES
Ajax and JSON Jeremy Shafer Department of MIS Fox School of Business
4.01 How Web Pages Work.
Ajax and JSON Jeremy Shafer Department of MIS Fox School of Business
Introduction to JavaScript
PHP and JSON Topics Review JSON.
Presentation transcript:

More APIs: Web Services CMPT 281

Announcements Project milestone Lab: – Web services examples

Overview What are web services Communication with web services – JSON Examples – Weather – Flickr

What is a web service? A way to provide ‘useful’ information in a way that can be accessed by websites – E.g., weather data, map data, search data “A software system designed to support interoperable machine-to-machine interaction over a network” (W3C)

What is a web service? An API on a remote web server – accessed through HTTP and higher-level protocols Web Application Web service A Web service B The Internet

JS libraries vs. web services JS libraries and web services both provide APIs – JS libraries: API is accessed through JavaScript functions – Web services: can’t call a JS function on another machine need a different approach for accessing the API

Communicating with Web Services Several approaches currently in use: – Remote procedure calls – Service-oriented architectures – Representational State Transfer (REST) REST: – Uses standard HTTP operations (e.g., GET) – ‘Stateless’: no state stored on the server

Communicating with Web Services Speaking REST: – Requests and responses – Requests are URIs – Responses are strings in standard formats XML JSON HTML

Communicating with Web Services What is in a request URI? – The web address of the server – Request parameters For example, a Flickr request: otos.search&api_key=av5a9e36bafa9cf9fc1b6a306a5 &text="octopus"&format=json&jsoncallback=handle

Communicating with Web Services ?method=flickr.photos.search &api_key=av5a9e36bafa9cf9fc1b6a306a5 &text="octopus“ &format=json &jsoncallback=handle

Communicating with Web Services JSON response JavaScript Object Notation A text string that JavaScript can interpret as an object

JSON object for a person { "firstName": "John", "lastName": "Smith", "age": 25, "address": { "streetAddress": "21 2nd Street“, "city": "New York", "postalCode": "10021“ } var customer =

Using JS objects Dot notation to access sub-parts: customer.firstName customer.address.city Same idea with JSON results – But, need to know the structure of the object! – Read the API documents – Inspect an example Helpful tool:

What do you get in a JSON reply? Not pictures, sounds, etc. Usually just URLs But you can use these to get the content Example JSON reply: Weather request

How to call web services from JS AJAX approach: var my_JSON_object = {}; var request = new XMLHttpRequest(); request.open( "GET", url, true ); request.onreadystatechange = function () { if (request.readyState == 4 && request.status == 200) { my_JSON_object = JSON.parse( request.responseText ); } }; http_request.send(null);

How to call web services from JS AJAX approach: var my_JSON_object = {}; var request = new XMLHttpRequest(); request.open( "GET", url, true ); request.onreadystatechange = function () { if (request.readyState == 4 && request.status == 200) { my_JSON_object = JSON.parse( request.responseText ); } }; http_request.send(null);

How to call web services from JS Problem: – Can only access APIs that are in the same web domain as the page itself

How to call web services from JS Problem: – Can only access APIs that are in the same web domain as the page itself Clever workaround: – JSONP – Makes use of the ‘open policy’ for tags

JSONP “JSON with Padding” Uses an encoded callback function The web service sends back JavaScript code The web page tells the web service what function to put in the code The code is run when the ‘script’ is loaded

JSONP Recall the structure of a request: ?method=flickr.photos.search &api_key=av5a9e36bafa9cf9fc1b6a306a5 &text="octopus“ &format=json &jsoncallback=handle

Examples Weather Flickr