Rest

Post on 27-Jun-2015

192 views 1 download

description

Palestra sobre REST para evento da Lab360.

Transcript of Rest

REST

Saturday, 2 June 2012

@CBSANCHEZ

• Programando desde 1997

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

• Leitor eXtreme

Saturday, 2 June 2012

INTEGRAÇÃO

Saturday, 2 June 2012

COM+

RMI

SÓ ENTRE ELES

CORBA(PELO MENOS ELE TENTOU)

Saturday, 2 June 2012

SOAPREST

AMIGO DA GAROTADA

Saturday, 2 June 2012

SOAP

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

• XML

•WS-*

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

Saturday, 2 June 2012

REST

• Transport HTTP/HTTPS

• XML/JSON/Outros

• Hypermedia

• Stateless

Saturday, 2 June 2012

SOA

ENTERPRISE

Saturday, 2 June 2012

REST

MOBILE

Saturday, 2 June 2012

O INÍCIO (WEB)

Saturday, 2 June 2012

FRAMEWORKS

GET POST

Saturday, 2 June 2012

PUT? DELETE? PRA QUE?

Saturday, 2 June 2012

ROY FIELDINGano: 2000

Saturday, 2 June 2012

REPRESENTATIONALSTATE

TRANSFER

Saturday, 2 June 2012

RESTa style of software architecture

Saturday, 2 June 2012

RESTFULimplementing such an architecture

Saturday, 2 June 2012

JSR 311: JAX-RS

JERSEY

RESTEASY

CXF

WCF TAMBÉM

RESTFULIE

Saturday, 2 June 2012

VAMOS PRO REST

Saturday, 2 June 2012

RESOURCE BASED

Saturday, 2 June 2012

• 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

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

Saturday, 2 June 2012

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

RECURSO

QUALQUER ABSTRAÇÃO! MESMO!

Saturday, 2 June 2012

REPRESENTAÇÃO

SEU RECURSO EM VÁRIAS FORMAS!

XHTMLXML

JSONCUSTOM

ATOM

Saturday, 2 June 2012

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

SEGURO

Sem efeitos colaterais no servidor!

Saturday, 2 June 2012

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

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

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

CRUDHYPERMEDIA

Saturday, 2 June 2012

CRUD

Saturday, 2 June 2012

CRUD TRADICIONAL

Saturday, 2 June 2012

CRUD RESTSaturday, 2 June 2012

CÓDIGOS HTTP

200 - OK

201 - OK, Created

204 - OK, No content

404 - Not Found

405 - Method Not Allowed

Saturday, 2 June 2012

HYPERMEDIA

Saturday, 2 June 2012

HYPERMEDIA

Links vem de HyperLinks...

HyperMedia vem do uso de HyperLinks...

Saturday, 2 June 2012

REPRESENTAÇÃO

A WEB É AGNOSTICA AO FORMATO,

SEU CLIENTE NÃO!

Saturday, 2 June 2012

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

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

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

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

RESTFULIE

• Java, Ruby, Objective-C

• Hypermedia

• Elegante!!

Saturday, 2 June 2012

RESTFULIE E VERBOS HTTP

• destroy, cancel, delete: DELETE

• update: PUT

• refresh, reload, show, latest: GET

• outros: POST

Saturday, 2 June 2012

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

TRANSAÇÕES

Saturday, 2 June 2012

TRANSAÇÕES COMPENSATÓRIAS

• Transações ACID

• Sistema sabe como desfazer

Saturday, 2 June 2012

TRY-CANCEL/CONFIRM

Saturday, 2 June 2012

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

MAIS INFORMAÇÕES

• Rest In Practice, Jim Webber

Saturday, 2 June 2012

MAIS INFORMAÇÕES

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

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

• http://jersey.java.net/

Saturday, 2 June 2012

OBRIGADO!Saturday, 2 June 2012