24
ANDRÉS AGUIAR [email protected] HTTP:// WEBLOGS.ASP.NET/AAGUIAR - @AAGUIAR REST y Silverlight 2.0

(20.05.2009) Cumuy Presenta - Más tecnologías interesantes para conocer - PPT 1

Embed Size (px)

DESCRIPTION

(20.05.2009) Cumuy Presenta - Más tecnologías interesantes para conocer - PPT 1

Citation preview

Page 1: (20.05.2009) Cumuy Presenta - Más tecnologías interesantes para conocer - PPT 1

A N D R É S A G U I A R

A A G U I A R @ I N F R A G I S T I C S . C O M

H T T P : / / W E B L O G S . A S P . N E T / A A G U I A R - @ A A G U I A R

REST y Silverlight 2.0

Page 2: (20.05.2009) Cumuy Presenta - Más tecnologías interesantes para conocer - PPT 1

REST

REST es un patrón de diseño

El término fue creado por Roy Fielding en sudisertación de Ph.D. en el año 2000

http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm

Page 3: (20.05.2009) Cumuy Presenta - Más tecnologías interesantes para conocer - PPT 1

Principio #1

Todo es un RECURSO

Ejemplos:

Clientes

Lugares

Productos

Page 4: (20.05.2009) Cumuy Presenta - Más tecnologías interesantes para conocer - PPT 1

Principio #2

Los Recursos tienen NOMBRES

Ejemplos:

http://acme.com/customers/coyote

http://world.com/usa/california/san_diego

xri://@acme*warehouse/(+rockets)

Page 5: (20.05.2009) Cumuy Presenta - Más tecnologías interesantes para conocer - PPT 1

Principio #3

Los recursos soportan VERBOS simples

Ejemplos:

Create, Read, Update, Delete

POST, GET, PUT, DELETE

Page 6: (20.05.2009) Cumuy Presenta - Más tecnologías interesantes para conocer - PPT 1

Principio #4

Los recursos tienenREPRESENTACIONES

Ejemplos:

HTML: text/html, application/xhtml+xml, …

XML: text/xml, application/atom+xml, …

Binary: image/png, application/pdf, …

Page 7: (20.05.2009) Cumuy Presenta - Más tecnologías interesantes para conocer - PPT 1

REST y HTTP

Get

Obtiene un Resource

Está garantido que no causa side-effects (Safe)

Cacheable

Post

Crea un nuevo recurso

Unsafe, el efecto de este verbo no esta definido por http

Page 8: (20.05.2009) Cumuy Presenta - Más tecnologías interesantes para conocer - PPT 1

REST y HTTP

Put

Actualiza un recurso existente

Se usa para crear recursos si el cliente conoce el Uri

Se puede llamar N veces y pasa lo mismo (idempotente)

Delete

Elimina un recurso

Se puede llamar N veces y pasa lo mismo (idempotente)

Page 9: (20.05.2009) Cumuy Presenta - Más tecnologías interesantes para conocer - PPT 1

REST y HTTP

Simple : basado en pocos principios y operaciones bien definidas

Escalable: se apiya en protocolos „stateless‟ y estado distribuido

En capas: premite cualquier cantidad de intermediarios como proxies, gateways y firewalls

Page 10: (20.05.2009) Cumuy Presenta - Más tecnologías interesantes para conocer - PPT 1

Modelado REST

Escenario: Búsqueda de itinerarios Busco itinerarios

Pido mas información

Reservo un pasaje

interface IFlightSystem

{Itineraries Search(string src, string dest);Details GetDetails(int itineraryId);Confirmation Reserve(itineraryId);

}

Page 11: (20.05.2009) Cumuy Presenta - Más tecnologías interesantes para conocer - PPT 1

http://quuxTravel.com/search?src=London&dest=NYC

<itineraries><itinerary src=“London“ dest=“NYC“ price=“400.03“><getDetails uri=“http://quuxTravel.com/details?itinerary=402“ />

<reserve uri=“http://reservations.com/quuxTravel?itinerary=402“/>

</itinerary>

<itinerary src=“London“ dest=“NYC“ price=“109.88“><getDetails

uri=“http://quuxTravel.com/details?itinerary=219“/><reserve

uri=“http://reservations.com/quuxTravel?itinerary=219“/></itinerary>

</itineraries>

Page 12: (20.05.2009) Cumuy Presenta - Más tecnologías interesantes para conocer - PPT 1

PURE REST

http:/../v1/Recurso/<Id> POST, GET, DELETE, PUT

No:

http:/../v1/Recurso/get/Id

http:/../v1/Recurso?Id=1

http:/../v1/Recurso.svc?Id=1

http:/../v1/Search?q=keyword GET

Page 13: (20.05.2009) Cumuy Presenta - Más tecnologías interesantes para conocer - PPT 1

Content Type

GET /customer/1 HTTP/1.1Accept: application/xml

HTTP/1.1 200 OKContent-Type: application/xml<Customer><Id>1</Id></Customer>

GET /customer/1 HTTP/1.1Accept: text/html

HTTP/1.1 200 OKContent-Type: text/html<html xmlns="http://www.w3.org/1999/xhtml"> ….

GET /customer/1 HTTP/1.1Accept: image/gif

HTTP/1.1 200 OKContent-Type: image/gifGif89a

Page 14: (20.05.2009) Cumuy Presenta - Más tecnologías interesantes para conocer - PPT 1

REST vs „Big Web Services‟

No Caching – HTTP Caching

WSDL vs WADL o /help)

UDDI vs Google Search

HTTPS y HTTP Auth vs WS-Security

WS-Federation vs protocolos abiertos tipo OpenID

WS-Transaction vs Nada

WS-Reliable Messaging vs Nada AtMostOnce, AtLeastOne, ExactlyOnce, InOrder

POST Exactly Once?

Page 15: (20.05.2009) Cumuy Presenta - Más tecnologías interesantes para conocer - PPT 1

REST Pragmático – Lo REST

Usar HTTP + XML como mecanismo de comunicación entre capas

Ventajas: Fácil de usar

Caching, Caching, Caching

Page 16: (20.05.2009) Cumuy Presenta - Más tecnologías interesantes para conocer - PPT 1

Caching

Los GETs se pueden cachear Cache-Control header

“no-cache”

“max-age=Segundos”, por ejemplo, “max-age=60”

Expires header

“Expires: Sat, 26 Jul 1997 05:00:00 GMT”

Pragma: no-cache

Page 17: (20.05.2009) Cumuy Presenta - Más tecnologías interesantes para conocer - PPT 1

Conditional GET

GET /icon-cart.gif HTTP/1.1

HTTP/1.1 200 OKContent-Length: 389Content-Type: image/gifLast-Modified: Fri, 08 Aug 2008 16:19:58 GMT

GET /icon-cart.gif HTTP/1.1If-Modified-Since: Fri, 08 Aug 2008 16:19:58 GMT

HTTP/1.1 304 Not Modified

Page 18: (20.05.2009) Cumuy Presenta - Más tecnologías interesantes para conocer - PPT 1

Conditional GET

GET /icon-cart.gif HTTP/1.1

HTTP/1.1 200 OKContent-Length: 389Content-Type: image/gifETag: "d0afa29638fec81:43a"

GET /icon-cart.gif HTTP/1.1If-None-Match: "d0afa29638fec81:43a“

HTTP/1.1 304 Not Modified

Page 19: (20.05.2009) Cumuy Presenta - Más tecnologías interesantes para conocer - PPT 1

Cache en el Browser

Configuración La copia del cache es nueva

La copia del cache es vieja

No hay directivas de cache

Cada vez que sevisita la página

No hay request RequestCondicional

RequestCondicional

Cada vez que seinicia IE

No hay request RequestCondicional

RequestCondicional

Automática No hay request RequestCondicional

Heurística

Nunca No hay request RequestCondicional

No hay request

Page 20: (20.05.2009) Cumuy Presenta - Más tecnologías interesantes para conocer - PPT 1

Heurística

Todas las siguientes condiciones: El recurso cacheado tiene un Content-Type que empieza con

image/.

El recurso cacheado tiene Last-Modified.

La URL cacheada no tiene un „?‟

“The cached resource has been conditionally requested at least once within the most recent 25 percent of its overall age in the cache”

http://msdn.microsoft.com/en-us/library/aa905731.aspx

Page 21: (20.05.2009) Cumuy Presenta - Más tecnologías interesantes para conocer - PPT 1

Conditional GET

GET /icon-cart.gif HTTP/1.1

HTTP/1.1 200 OKCache-Control: max-age=1Content-Length: 389Content-Type: image/gifLast-Modified: Fri, 08 Aug 2008 16:19:58 GMT

GET /icon-cart.gif HTTP/1.1If-Modified-Since: Fri, 08 Aug 2008 16:19:58 GMT

HTTP/1.1 304 Not Modified

Page 22: (20.05.2009) Cumuy Presenta - Más tecnologías interesantes para conocer - PPT 1

REST in SL

Http Request son asincrónicos

SL 2 no permite leer headers de requests o requestsque retornen <> HTTP 2XX No „304 Not Modified‟

No permite PUT/DELETE

Page 23: (20.05.2009) Cumuy Presenta - Más tecnologías interesantes para conocer - PPT 1

Server REST

Http Handlers

ASP.NET MVC

WCF REST support

Page 24: (20.05.2009) Cumuy Presenta - Más tecnologías interesantes para conocer - PPT 1

GO TO Visual Studio