Rest

51
REST Saturday, 2 June 2012

description

Palestra sobre REST para evento da Lab360.

Transcript of Rest

Page 1: Rest

REST

Saturday, 2 June 2012

Page 2: Rest

@CBSANCHEZ

• Programando desde 1997

• LISP, C++, Java, Ruby, outras

• Leitor eXtreme

Saturday, 2 June 2012

Page 3: Rest

INTEGRAÇÃO

Saturday, 2 June 2012

Page 4: Rest

COM+

RMI

SÓ ENTRE ELES

CORBA(PELO MENOS ELE TENTOU)

Saturday, 2 June 2012

Page 5: Rest

SOAPREST

AMIGO DA GAROTADA

Saturday, 2 June 2012

Page 6: Rest

SOAP

• Transporte Genérico (HTTP/HTTPS, JMS, SMTP)

• XML

•WS-*

• Statefull (WS-Security/WS-Coordination/WS-Transaction)

Saturday, 2 June 2012

Page 7: Rest

REST

• Transport HTTP/HTTPS

• XML/JSON/Outros

• Hypermedia

• Stateless

Saturday, 2 June 2012

Page 8: Rest

SOA

ENTERPRISE

Saturday, 2 June 2012

Page 9: Rest

REST

MOBILE

Saturday, 2 June 2012

Page 10: Rest

O INÍCIO (WEB)

Saturday, 2 June 2012

Page 11: Rest

FRAMEWORKS

GET POST

Saturday, 2 June 2012

Page 12: Rest

PUT? DELETE? PRA QUE?

Saturday, 2 June 2012

Page 13: Rest

ROY FIELDINGano: 2000

Saturday, 2 June 2012

Page 14: Rest

REPRESENTATIONALSTATE

TRANSFER

Saturday, 2 June 2012

Page 15: Rest

RESTa style of software architecture

Saturday, 2 June 2012

Page 16: Rest

RESTFULimplementing such an architecture

Saturday, 2 June 2012

Page 17: Rest

JSR 311: JAX-RS

JERSEY

RESTEASY

CXF

WCF TAMBÉM

RESTFULIE

Saturday, 2 June 2012

Page 18: Rest

VAMOS PRO REST

Saturday, 2 June 2012

Page 19: Rest

RESOURCE BASED

Saturday, 2 June 2012

Page 20: Rest

• Todos os recursos (resources) são identificáveis

• Um recurso possui várias representações

• Link entre os recursos

• Usar os métodos da plataforma

• Comunicação stateless

PRINCÍPIOS

Saturday, 2 June 2012

Page 21: Rest

ID DE RECURSOShttp://gdata.youtube.com/feeds/users/MysteryGuitarMan

Saturday, 2 June 2012

Page 22: Rest

ID DE RECURSOS

• http://restbucks.com/customers/1234

• http://restbucks.com/orders/2007/10/776654

• http://restbucks.com/customers/1234/products

• http://restbucks.com/products?brand=sony

Saturday, 2 June 2012

Page 23: Rest

RECURSO

QUALQUER ABSTRAÇÃO! MESMO!

Saturday, 2 June 2012

Page 24: Rest

REPRESENTAÇÃO

SEU RECURSO EM VÁRIAS FORMAS!

XHTMLXML

JSONCUSTOM

ATOM

Saturday, 2 June 2012

Page 25: Rest

LINK ENTRE RECURSOS

<order self='http://restbucks.com/customers/1234'>

<amount>2</amount>

<product ref='http://restbucks.com/products/4554' />

<customer ref='http://restbucks.com/customers/1234' />

</order>

Saturday, 2 June 2012

Page 26: Rest

SEGURO

Sem efeitos colaterais no servidor!

Saturday, 2 June 2012

Page 27: Rest

IDEMPOTENTE

É a propriedade de certas operações na matemática e computação onde o estado do recurso/aplicação não se modifica após multiplas invocações.

Saturday, 2 June 2012

Page 28: Rest

MÉTODOS PADRÃO

• GET – Seguro, Idempotente – Recupera um recurso

• PUT – Idempotente – Cria ou atualiza um recurso identificado por uma URI

•DELETE – Idempotente – Exclui um recurso

• POST – Inseguro – Cria um recurso

Saturday, 2 June 2012

Page 29: Rest

COMUNICAÇÃO STATELESS

• Estado no recurso ou no cliente

• Reduz o overload do server

• Reduz o acoplamento do cliente com o servidor

Saturday, 2 June 2012

Page 30: Rest

CRUDHYPERMEDIA

Saturday, 2 June 2012

Page 31: Rest

CRUD

Saturday, 2 June 2012

Page 32: Rest

CRUD TRADICIONAL

Saturday, 2 June 2012

Page 33: Rest

CRUD RESTSaturday, 2 June 2012

Page 34: Rest

CÓDIGOS HTTP

200 - OK

201 - OK, Created

204 - OK, No content

404 - Not Found

405 - Method Not Allowed

Saturday, 2 June 2012

Page 35: Rest

HYPERMEDIA

Saturday, 2 June 2012

Page 36: Rest

HYPERMEDIA

Links vem de HyperLinks...

HyperMedia vem do uso de HyperLinks...

Saturday, 2 June 2012

Page 37: Rest

REPRESENTAÇÃO

A WEB É AGNOSTICA AO FORMATO,

SEU CLIENTE NÃO!

Saturday, 2 June 2012

Page 38: Rest

REPRESENTAÇÃO

<order xmlns="http://schemas.restbucks.com">

<location>takeAway</location>

<item>

<name>latte</name>

<quantity>1</quantity>

<size>small</size>

</item>

<cost>2.59</costs>

<status>payment-expected</status>

<order>

Saturday, 2 June 2012

Page 39: Rest

REPRESENTAÇÃO MELHOR

<order xmlns="http://schemas.restbucks.com">

<location>takeAway</location>

<item>

<name>latte</name>

<quantity>1</quantity>

<size>small</size>

</item>

<cost>2.59</costs>

<status>payment-expected</status>

<payment>http://restbucks.com/payment/1234</payment>

<cancel>http://restbucks.com/payment/1234</cancel>

</order>

Saturday, 2 June 2012

Page 40: Rest

UMA REPRESENTAÇÃO BEM MELHOR

<order xmlns="http://schemas.restbucks.com">

<location>takeAway</location>

<item>

<name>latte</name>

<quantity>1</quantity>

<size>small</size>

</item>

<cost>2.59</costs>

<status>payment-expected</status>

<link action="payment" href="http://restbucks.com/payment/1234" />

<link action="cancel" href="http://restbucks.com/payment/1234" />

</order>

Saturday, 2 June 2012

Page 41: Rest

UMA REPRESENTAÇÃO BEM MELHOR (AINDA!)

<order xmlns="http://schemas.restbucks.com">

<location>takeAway</location>

<item>

<name>latte</name>

<quantity>1</quantity>

<size>small</size>

</item>

<cost>2.59</costs>

<status>payment-expected</status>

<atom:link rel="payment" href="http://restbucks.com/payment/1234" />

<atom:link rel="cancel" href="http://restbucks.com/payment/1234" />

</order>

Saturday, 2 June 2012

Page 42: Rest

RESTFULIE

• Java, Ruby, Objective-C

• Hypermedia

• Elegante!!

Saturday, 2 June 2012

Page 43: Rest

RESTFULIE E VERBOS HTTP

• destroy, cancel, delete: DELETE

• update: PUT

• refresh, reload, show, latest: GET

• outros: POST

Saturday, 2 June 2012

Page 44: Rest

CLIENTE RESTFULIE

// lista de relações

List<Relation> relations = resource(order).getRelations();

Order order = new Order();

// envia um Pedido

order = service("http://restbucks.com/order").post(order);

// cancela uma ordem

resource(order).getRelation("cancel").execute();

Saturday, 2 June 2012

Page 45: Rest

TRANSAÇÕES

Saturday, 2 June 2012

Page 46: Rest

TRANSAÇÕES COMPENSATÓRIAS

• Transações ACID

• Sistema sabe como desfazer

Saturday, 2 June 2012

Page 47: Rest

TRY-CANCEL/CONFIRM

Saturday, 2 June 2012

Page 48: Rest

TRY-CANCEL/CONFIRM

<order xmlns="http://schemas.restbucks.com">

<location>takeAway</location>

<item>

<name>latte</name>

<quantity>1</quantity>

<size>small</size>

</item>

<cost>2.59</costs>

<status>payment-expected</status>

<atom:link rel="payment" href="http://restbucks.com/payment/1234" />

<atom:link rel="cancel" href="http://restbucks.com/payment/1234" />

</order>

Saturday, 2 June 2012

Page 49: Rest

MAIS INFORMAÇÕES

• Rest In Practice, Jim Webber

Saturday, 2 June 2012

Page 50: Rest

MAIS INFORMAÇÕES

• http://www.infoq.com/articles/rest-introduction

• http://restfulie.caelum.com.br/

• http://jersey.java.net/

Saturday, 2 June 2012

Page 51: Rest

OBRIGADO!Saturday, 2 June 2012