54
Internet Technologie s #6 REST SOAP AJAX

Internet Technologies #6 REST SOAP AJAX. Agenda REST SOAP AJAX

Embed Size (px)

DESCRIPTION

REST APPLICATION SERVERS TODAY

Citation preview

Page 1: Internet Technologies #6 REST SOAP AJAX. Agenda  REST  SOAP  AJAX

Internet Technologies#6 REST SOAP AJAX

Page 2: Internet Technologies #6 REST SOAP AJAX. Agenda  REST  SOAP  AJAX

Agenda

RESTSOAPAJAX

Page 3: Internet Technologies #6 REST SOAP AJAX. Agenda  REST  SOAP  AJAX

RESTAPPLICATION SERVERS TODAY

Page 4: Internet Technologies #6 REST SOAP AJAX. Agenda  REST  SOAP  AJAX

REST - what is it?

" REST " – was coined by Roy Fielding in his Ph.D. dissertation [1] to describe a design pattern for implementing networked systems.[1] http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm

Page 5: Internet Technologies #6 REST SOAP AJAX. Agenda  REST  SOAP  AJAX

How it works?

The Client references a Web resource using a URL.

A representation of the resource is returned (in this case as an HTML

document).The representation (e.g.,

Boeing747.html) places the client in a new state.

Page 6: Internet Technologies #6 REST SOAP AJAX. Agenda  REST  SOAP  AJAX

How it works

When the client selects a hyperlink in Boeing747.html, it accesses another resource.

The new representation places the client application into yet another state.

Thus, the client application transfers state with each resource representation.

Page 7: Internet Technologies #6 REST SOAP AJAX. Agenda  REST  SOAP  AJAX

REST - what is it?

"Representational State Transfer is intended to evoke an image of how a well-designed Web application behaves: a network of web pages (a virtual state-machine), where the user progresses through an application by selecting links (state transitions), resulting in the next page (representing the next state of the application) being transferred to the user and rendered for their use."

- Roy Fielding

Page 8: Internet Technologies #6 REST SOAP AJAX. Agenda  REST  SOAP  AJAX

REST - what is it?

Not a standard! Just a design pattern… that prescribes the use of standards:

HTTPURLXML/HTML/GIF/JPEG/etc.

(resource representations) text/xml, text/html, image/gif,

image/jpeg, etc. (MIME types)

Page 9: Internet Technologies #6 REST SOAP AJAX. Agenda  REST  SOAP  AJAX

REST - basics

Create a resource for every service. Identify each resource using a URL. The data that a Web service returns

should link to other data. Thus, design your data as a network of information.

Contrast with OO design, which says to encapsulate information - don’t do it!

Page 10: Internet Technologies #6 REST SOAP AJAX. Agenda  REST  SOAP  AJAX

REST - basics

All interactions between a client and a web service are done with simple operations. Most web interactions are done using HTTP and just four operations: retrieve information (HTTP GET)create information (HTTP PUT)update information (HTTP POST)delete information (HTTP DELETE)

Page 11: Internet Technologies #6 REST SOAP AJAX. Agenda  REST  SOAP  AJAX

Features

platform independent language independent standards-based no problems with firewalls etc.

No built in mechanisms for: Security Cryptography Session management Quality of Service …

Page 12: Internet Technologies #6 REST SOAP AJAX. Agenda  REST  SOAP  AJAX

Used by…

…many serious servicesTwitterAmazon services(S3

storage solution)FlickrAtom…

Page 13: Internet Technologies #6 REST SOAP AJAX. Agenda  REST  SOAP  AJAX

Resource representations

Often XML but not the only available option often:

CSV (for large amounts of data) JSON (JavaScript Object Notation)

Page 14: Internet Technologies #6 REST SOAP AJAX. Agenda  REST  SOAP  AJAX

Recommendations

Don’t use physical URLs, use logical ones http://www.acme.com/inventory/product003.xml vs http://www.acme.com/inventory/product/003

Requests should not return large amounts of data use paging

Don’t change resource formats lightly provide additional ones

Page 15: Internet Technologies #6 REST SOAP AJAX. Agenda  REST  SOAP  AJAX

Recommendations

Don’t make the client to construct new action URLs make them a part of the resource

GET requests should not change server state - this is what POST, DELETE, PATCH and so on are for…

Don’t rely on cookies and so on

Page 16: Internet Technologies #6 REST SOAP AJAX. Agenda  REST  SOAP  AJAX

SOAP web services

Page 17: Internet Technologies #6 REST SOAP AJAX. Agenda  REST  SOAP  AJAX

Web Services

A Web service is a method of communication between two electronic devices over a network. It is a software function provided at a network address over the Web with the service always on as in the concept of utility computing.

Page 18: Internet Technologies #6 REST SOAP AJAX. Agenda  REST  SOAP  AJAX

Web Services

encapsulated - implementation is not visible to the user

loosely coupled - modifications of implementation (not interface!) should not generate the change propagation problem

contracted - descriptions of functions and their interface specifications are publicly available

Page 19: Internet Technologies #6 REST SOAP AJAX. Agenda  REST  SOAP  AJAX

WS architecture

client,service providerservice broker (optional)

publishing of service descriptions

service lookup

Page 20: Internet Technologies #6 REST SOAP AJAX. Agenda  REST  SOAP  AJAX

WS architecture

Page 21: Internet Technologies #6 REST SOAP AJAX. Agenda  REST  SOAP  AJAX

WS architecture

use of specific, popular technologiesURL for addressingSOAP for transport (HTTP-

based)XML as message format

Page 22: Internet Technologies #6 REST SOAP AJAX. Agenda  REST  SOAP  AJAX

SOAP

stateless, one-way protocol based on HTTP may utilize other protocols (nobody does it

really) allows construction of more complex

communication models specifies structure for XML message

exchange mandatory and optional message elements encoding and transmission

does not determine application semantics, coding paradigm etc.

Page 23: Internet Technologies #6 REST SOAP AJAX. Agenda  REST  SOAP  AJAX

WSDL

W3C specification used to provide machine-readable WS description

Based on XML Defines service interface, not

service semanticsabstract interface - independent

from transport protocol or programming language

Page 24: Internet Technologies #6 REST SOAP AJAX. Agenda  REST  SOAP  AJAX

WSDL

definition contains the general part:

data types definitions message definitions port type definitions

and the specific part binding definitions service definitions

Page 25: Internet Technologies #6 REST SOAP AJAX. Agenda  REST  SOAP  AJAX

UDDI

Universal Description, Discovery and Integration

White Pages – address, contact, identifiers

Yellow Pages - categorization based on predefined taxonomies

Green Pages – technical informations

Page 26: Internet Technologies #6 REST SOAP AJAX. Agenda  REST  SOAP  AJAX

UDDI

Specification published in 2000 Vision of widely available services

commercialdynamically integrated with

applications Last public UDDI nodes

maintained by Microsoft, IBM and SAP closed in January 2006

Page 27: Internet Technologies #6 REST SOAP AJAX. Agenda  REST  SOAP  AJAX

Web Services in practice

Two service construction scenarios: Top-down:

design the servicecreate WSDgenerate stub and skeletonimplement

Bottom-up: take existing implementationgenerate WSDL based on it, create

stubs and skeletons from it

Page 28: Internet Technologies #6 REST SOAP AJAX. Agenda  REST  SOAP  AJAX

Web Services in practice

multiple additional specificationsWS-SecurityWS-SignatureWS-EncryptionWS-TrustWS-Notification…

Page 29: Internet Technologies #6 REST SOAP AJAX. Agenda  REST  SOAP  AJAX

AJaX

Page 30: Internet Technologies #6 REST SOAP AJAX. Agenda  REST  SOAP  AJAX

AJaX

Old ideas come back in new form Cycles in the approach to application

architecture: Terminals „thick” client applications web pages dynamic web pages

Page 31: Internet Technologies #6 REST SOAP AJAX. Agenda  REST  SOAP  AJAX

AJaX

Drawbacks of „thin” web page applications: user interface „feel” radically different in

comparison to desktop applications

Page 32: Internet Technologies #6 REST SOAP AJAX. Agenda  REST  SOAP  AJAX

What is AJaX

A name given to an existing approach to building dynamic web applications

Web pages use JavaScript to make asynchronous calls to web-based services that typically return XML

Uses a JavaScript class called XMLHttpRequest

Page 33: Internet Technologies #6 REST SOAP AJAX. Agenda  REST  SOAP  AJAX

What is AJaX

allows user to continue interacting with web page while waiting for data to be returned

page can be updated without refreshing browser

results in a better user experience there are AJaX libraries that reduce the amount

of JavaScript code that must be written

Page 34: Internet Technologies #6 REST SOAP AJAX. Agenda  REST  SOAP  AJAX

What is AJaX

A is for “asynchronous” requests can be made asynchronously or

synchronously both techniques allow web page to be updated

without refreshing it anything useful the user can do while

processing request? if yes then use asynchronous, otherwise use

synchronous

Page 35: Internet Technologies #6 REST SOAP AJAX. Agenda  REST  SOAP  AJAX

What is AJaX

Ja is for “JavaScript” typically JavaScript is used on the client-side (in

the browser) only programming language supported out-of-the-

box by most web browsers can use any language on server-side that can

accept HTTP requests and return HTTP responses Java servlets, Ruby servlets, CGI scripts, …

Page 36: Internet Technologies #6 REST SOAP AJAX. Agenda  REST  SOAP  AJAX

What is AJaX

X is for “XML” request and response messages can contain

XML can really contain any text (single text value,

delimited text, …)

Page 37: Internet Technologies #6 REST SOAP AJAX. Agenda  REST  SOAP  AJAX

What is AJaX

Traditional approach to building web applications: URL used to navigate between web pages, but

also as interaction tool AJaX approach:

communication with server without sending requests for another page

Page 38: Internet Technologies #6 REST SOAP AJAX. Agenda  REST  SOAP  AJAX

Components of AJaX

XMLHttpRequest object XML, XSLT – exchange and transformation of

data XHTML, CSS – standard presentation tools DOM – interaction with document, document

updates JavaScript – client-side scripts

Page 39: Internet Technologies #6 REST SOAP AJAX. Agenda  REST  SOAP  AJAX

How it works

XMLHttpRequest - a JavaScript class supported by most web browsers Allows HTTP requests to be sent from JavaScript

code to send multiple, concurrent requests, use a different XMLHttpRequest instance for each

HTTP responses are processed by “handler” functions – in client-side JavaScript

Page 40: Internet Technologies #6 REST SOAP AJAX. Agenda  REST  SOAP  AJAX

First issue

code to create an XMLHttpRequest object differs between browsers

can use a JavaScript library to hide the differences

Page 41: Internet Technologies #6 REST SOAP AJAX. Agenda  REST  SOAP  AJAX

XMLHttpRequest Properties

(partial list) readyState

0 = UNINITIALIZED; open not yet called 1 = LOADING; send for request not yet called 2 = LOADED; send called, headers and status are

available 3 = INTERACTIVE; downloading response, responseText only partially set 4 = COMPLETED; finished downloading response

Page 42: Internet Technologies #6 REST SOAP AJAX. Agenda  REST  SOAP  AJAX

XMLHttpRequest Properties

responseText response as text; null if error occurs or ready

state < 3 responseXML

response as DOM Document object; null if error occurs or ready state < 3

status – integer status code statusText – string status onreadystatechange – assign a function called on

each state change

Page 43: Internet Technologies #6 REST SOAP AJAX. Agenda  REST  SOAP  AJAX

XMLHttpRequest Properties

(partial list) Basic methods

open(method, url[, async]) – initializes a new HTTP request

method can be "GET", "POST", "PUT" or "DELETE" url must be an HTTP URL (start with "http://") async is a boolean indicating whether request

should be sent asynchronously defaults to true

Page 44: Internet Technologies #6 REST SOAP AJAX. Agenda  REST  SOAP  AJAX

XMLHttpRequest Properties

send(body) – sends HTTP request abort() – called after send() to cancel request void setRequestHeader(name, value) String getResponseHeader(name) String getAllResponseHeaders()

returns a string where „header: value” pairs are delimited by carriage returns

Page 45: Internet Technologies #6 REST SOAP AJAX. Agenda  REST  SOAP  AJAX

Sample call

function getResource(url) {

if (window.XMLHttpRequest) { // Mozilla etc.

xhr =new XMLHttpRequest();

xhr.onreadystatechange=handleChange; // callback

xhr.open("GET", url, true);

xhr.send(null);

}

else if (window.ActiveXObject) { // Internet Exporer

xhr=new ActiveXObject("Microsoft.XMLHTTP");

if (xhr) {

xhr.onreadystatechange=handleChange;

xhr.open("GET",url,true); xhr.send();

} } }

Page 46: Internet Technologies #6 REST SOAP AJAX. Agenda  REST  SOAP  AJAX

Sample response handler

function handleChange() {

if (xmlhttp.readyState==4) {

if (xmlhttp.status==200) {

// ...get data, update view...

}

} }

Page 47: Internet Technologies #6 REST SOAP AJAX. Agenda  REST  SOAP  AJAX

Using JSON

var my_JSON_object = {}; var http_request = new XMLHttpRequest(); http_request.open("GET", url, true); http_request.onreadystatechange = function () {

var done = 4, ok = 200; if (http_request.readyState == done

&& http_request.status == ok) { my_JSON_object = JSON.parse(http_request.responseText); }

}; http_request.send(null);

Page 48: Internet Technologies #6 REST SOAP AJAX. Agenda  REST  SOAP  AJAX

We’ve been here before…

The new part is the XMLHttpRequest object and asynchronous call (not really ;) ), the rest has been done before

Hidden Frames IE5+, Mozilla 1.0+, Safari 1.2+, and Opera 7.6+

Java Applets

Page 49: Internet Technologies #6 REST SOAP AJAX. Agenda  REST  SOAP  AJAX

Why is it popular?

Google helped popularize, and legitimize it in GMail

Increase Usability of Web Applications Rich Internet Applications without Flash Save Bandwidth Download only data you need Faster interfaces (sometimes)

Page 50: Internet Technologies #6 REST SOAP AJAX. Agenda  REST  SOAP  AJAX

Why is it bad?

Breaks back button support and bookmarking URL's don't change as state changes Cross Browser Issues can be a pain JavaScript may tax older machines CPU Can't access domains other than the calling domain May be disabled (for security reasons) or not

available on some browsers Debugging is difficult

Page 51: Internet Technologies #6 REST SOAP AJAX. Agenda  REST  SOAP  AJAX

Why is Microsoft so evil?

As usual the IE handles things differently to the other browsers

but… they did this first so it is rather hard to blame them IE7 includes support for both „IE-style” and

„rest of the world-style” HttpRequests… there are some issues, however

Page 52: Internet Technologies #6 REST SOAP AJAX. Agenda  REST  SOAP  AJAX

When NOT to use AJaX

Just because it is cool and shiny For navigation To display static content

Page 53: Internet Technologies #6 REST SOAP AJAX. Agenda  REST  SOAP  AJAX

When you should use AJaX

Real-time user-server interaction Validation of data based on server-side

resources Displaying content that should be hidden from

search engines

Page 54: Internet Technologies #6 REST SOAP AJAX. Agenda  REST  SOAP  AJAX

Questions?