Arquitetura: chega de mesmice

Post on 03-Jul-2015

1.511 views 1 download

description

Palestra sobre arquitetura de sistemas distribuídos e integração entre sistemas que não possuiam previsão.

Transcript of Arquitetura: chega de mesmice

Arquitetura: chega de mesmiceGuilherme Silveira

Tuesday, October 12, 2010

Guilherme Silveiraguilherme.silveira@caelum.com.br

Tuesday, October 12, 2010

são paulo

Tuesday, October 12, 2010

são paulo

Tuesday, October 12, 2010

são paulo

Tuesday, October 12, 2010

são paulo

Tuesday, October 12, 2010

são paulo

Tuesday, October 12, 2010

Guilherme Silveiraguilherme.silveira@caelum.com.br

2002 guj.com.br2003 vraptor2004 caelum.com.br xp, xstream2006 scrum2009 restfulie, lean2010 tectura.com.br

Tuesday, October 12, 2010

calendar.com

travel.com company.com

bank.com

Tuesday, October 12, 2010

CORBAheaven?

Tuesday, October 12, 2010

EJBheaven?

Tuesday, October 12, 2010

SOAPheaven?

Tuesday, October 12, 2010

what is REST?

Tuesday, October 12, 2010

what is the future of integration over the web?

Tuesday, October 12, 2010

what was REST?

Tuesday, October 12, 2010

Restful

Services

Web

Tuesday, October 12, 2010

Restful

Servicescreate a saas account

Web

Tuesday, October 12, 2010

Restful

Servicescreate a saas account

freeze account

Web

Tuesday, October 12, 2010

Restful

Servicescreate a saas account

freeze account

reactivate account

Web

Tuesday, October 12, 2010

Restful Services

Web

Tuesday, October 12, 2010

Restful Services

http

Web

Tuesday, October 12, 2010

Restful Services

http

port 80

Web

Tuesday, October 12, 2010

Restful Services

http

port 80

firewall heaven

Web

Tuesday, October 12, 2010

Restful

ServicesWeb

Tuesday, October 12, 2010

Restful

Services

xml, json

Web

Tuesday, October 12, 2010

Restful

Services

xml, json

get, post, ...

Web

Tuesday, October 12, 2010

Restful ServicesWeb

But what about Hypermidia?What about consumers?

as of 2009

Tuesday, October 12, 2010

Restful ServicesWeb

There is much more!

But what about Hypermidia?What about consumers?

as of 2009

Tuesday, October 12, 2010

unresttrips.com: flight details

<?xml version="1.0" encoding="UTF-8" standalum="yes"?><flight> <information> <from>sao paulo</from> <to>seoul</to> </information>  <value>900.00</value></flight>

Tuesday, October 12, 2010

service locator when integrating:

coupling++

guilherme

unresttrips.com

unrest pay

Tuesday, October 12, 2010

service locator when integrating:

coupling++

guilherme

unresttrips.com

unrest pay

Tuesday, October 12, 2010

resttrips.com: flight details

<?xml version="1.0" encoding="UTF-8" standalum="yes"?><flight> <information> <from>sao paulo</from> <to>seoul</to> </information>  <value>900.00</value> <link rel="payment" href="http://resttrips.com/payment/custom"/></flight>

Tuesday, October 12, 2010

resttrips.com: flight details

<?xml version="1.0" encoding="UTF-8" standalum="yes"?><flight> <information> <from>sao paulo</from> <to>seoul</to> </information>  <value>900.00</value> <link rel="payment" href="http://resttrips.com/payment/custom"/></flight>

Tuesday, October 12, 2010

resttrips.com: making the payment

flight = Client.at('http://resttrips.com/f/574XR4').get();

confirmation = flight.getLink("payment"). patch(cardInformation, value);

Tuesday, October 12, 2010

resttrips.com: making the payment

flight = Client.at('http://resttrips.com/f/574XR4').get();

confirmation = flight.getLink("payment"). patch(cardInformation, value);

Tuesday, October 12, 2010

resttrips.com: changing its payment provider

<?xml version="1.0" encoding="UTF-8" standalum="yes"?><flight> <information> <from>sao paulo</from> <to>seoul</to> </information>  <value>900.00</value> <link rel="payment" href="http://paysite.com/custom"/></flight>

Tuesday, October 12, 2010

resttrips.com: changing its payment provider

<?xml version="1.0" encoding="UTF-8" standalum="yes"?><flight> <information> <from>sao paulo</from> <to>seoul</to> </information>  <value>900.00</value> <link rel="payment" href="http://paysite.com/custom"/></flight>

Tuesday, October 12, 2010

dependency injection when integrating:

coupling--

guilherme

resttrips.com

paysite.com

restrips pay

Tuesday, October 12, 2010

dependency injection when integrating:

coupling--

guilherme

resttrips.com

paysite.com

restrips pay

Tuesday, October 12, 2010

trip = resource

payment = resource

http://kayak.com/f/574XR4

any_uri_unknown_at_compile_time

Tuesday, October 12, 2010

Tuesday, October 12, 2010

Tuesday, October 12, 2010

Tuesday, October 12, 2010

Tuesday, October 12, 2010

não viajo sozinho

Tuesday, October 12, 2010

meu amigo @sergio_caelum

Tuesday, October 12, 2010

meu amigo @sergio_caelum

Bilu biluTuesday, October 12, 2010

flight = Client.at('http://resttrips.com/f/574XR4').get();

confirmation = flight.getLink("payment"). patch(cardInformation, value/2);

// send the payment link to another part of the web

flight = Client.at('http://resttrips.com/f/574XR4').get();

confirmation = flight.getLink("payment"). patch(cardInformation, value/2);

resttrips.com: sharing a trip

Tuesday, October 12, 2010

flight = Client.at('http://resttrips.com/f/574XR4').get();

confirmation = flight.getLink("payment"). patch(cardInformation, value/2);

// send the payment link to another part of the web

flight = Client.at('http://resttrips.com/f/574XR4').get();

confirmation = flight.getLink("payment"). patch(cardInformation, value/2);

resttrips.com: sharing a trip

Tuesday, October 12, 2010

flight = Client.at('http://resttrips.com/f/574XR4').get();

confirmation = flight.getLink("payment"). patch(cardInformation, value/2);

// send the payment link to another part of the web

flight = Client.at('http://resttrips.com/f/574XR4').get();

confirmation = flight.getLink("payment"). patch(cardInformation, value/2);

resttrips.com: sharing a trip

Tuesday, October 12, 2010

flight = Client.at('http://resttrips.com/f/574XR4').get();

confirmation = flight.getLink("payment"). patch(cardInformation, value/2);

// send the payment link to another part of the web

flight = Client.at('http://resttrips.com/f/574XR4').get();

confirmation = flight.getLink("payment"). patch(cardInformation, value/2);

resttrips.com: sharing a trip

Tuesday, October 12, 2010

myself = Client.at('http://users.calendar.com') .with(auth).get();

myself.link("calendar").patch(flight.link("self"));

calendar: integrating my systems

Tuesday, October 12, 2010

myself = Client.at('http://users.calendar.com') .with(auth).get();

myself.link("calendar").patch(flight.link("self"));

calendar: integrating my systems

Tuesday, October 12, 2010

me.link("calendar").patch(link_to_birthday_list)me.link("calendar").patch(link_to_hotel_reservation)me.link("calendar").patch(link_to_trip_details)

calendar: more examples

Tuesday, October 12, 2010

so what?

Tuesday, October 12, 2010

so what?

Any update on the flight ==> reflects hereAny update on the hotel ==> reflects hereAny update on the meeting ==> reflects here

Tuesday, October 12, 2010

so what?

Any update on the flight ==> reflects hereAny update on the hotel ==> reflects hereAny update on the meeting ==> reflects here

don’t just u

se, integrate!

Tuesday, October 12, 2010

so what? that was just keeping an URI.

Tuesday, October 12, 2010

so what? that was just keeping an URI.

Remove ==> Cancels the flightRemove ==> Cancels the reservationRemove ==> Emails your coworkers

Tuesday, October 12, 2010

so what? that was just keeping an URI.

Remove ==> Cancels the flightRemove ==> Cancels the reservationRemove ==> Emails your coworkers

do not central

ize control!

Tuesday, October 12, 2010

integration over the web

INTEGRATION is DECENTRALIZING the CONTROLdelegating to multiple agents

distributed systems

Tuesday, October 12, 2010

does our ‘rest’ sites in 2010 work

this way?

Tuesday, October 12, 2010

so what? that was just keeping an URI.

Remove ==> Cancels the flightRemove ==> Cancels the reservationRemove ==> Emails your coworkers

Tuesday, October 12, 2010

so what? that was just keeping an URI.

Remove ==> Cancels the flightRemove ==> Cancels the reservationRemove ==> Emails your coworkers

but which format?

Tuesday, October 12, 2010

mas qual o formato dopagamento ou calendário?

Tuesday, October 12, 2010

#json, #xml, #soap #etc?

Tuesday, October 12, 2010

qual #json, #xml #etc?

Tuesday, October 12, 2010

exercise

Tuesday, October 12, 2010

who is that guy?

Tuesday, October 12, 2010

quem é essa?

Tuesday, October 12, 2010

fácil? e ela?

Tuesday, October 12, 2010

fácil? e ela?

não é minha filha!

Tuesday, October 12, 2010

conteúdo sem semânticanão tem valor!

Tuesday, October 12, 2010

so what?

Tuesday, October 12, 2010

so what?

micro formats, media types, rdf etc

Tuesday, October 12, 2010

so what?

micro formats, media types, rdf etc

micro formats

with hyperlinks!

Tuesday, October 12, 2010

integration over the web

Tuesday, October 12, 2010

#json, @sergio_caelum

Tuesday, October 12, 2010

#?

Tuesday, October 12, 2010

de onde veio o # e o @?

Tuesday, October 12, 2010

“watching @guilhermecaelum #qconsp *10 great talk”

Atenção: esse tweet é só uma sugestão!

Tuesday, October 12, 2010

controlled vocabulary

Tuesday, October 12, 2010

emergiu no twitter, por exemplo

Tuesday, October 12, 2010

inventar antes o controlled vocabulary?

Tuesday, October 12, 2010

top down? Big Design Up Front

O monstro do lago SOAP, longa de 2001

Tuesday, October 12, 2010

economizando

# busca um voodef voos_de(site)  base = Restfulie.at(site).get  voos = base.link("opensearch").get.fill("flight").with(:from => "GRU", :to => "JFK").getend

voos = voos_de("kayak")voos << voos_de("tam")voos << voos_de("gol")voos << voos_de("cvc")

voo_mais_barato(voos).link("payment").post(inferno_do_cartao)

Tuesday, October 12, 2010

banco

voo = voo_mais_barato(voos)

banco = Restfulie.at("meubanco").auth(eu).get

auth = banco.cartoes["lisa"] .authorization(1.min, voo.preco)voo.link("payment").post(auth)

mais_barato(voos).link("payment")...

Tuesday, October 12, 2010

email

Tuesday, October 12, 2010

Tuesday, October 12, 2010

email

guilherme super viagem

Tuesday, October 12, 2010

email

guilherme super viagem

Tuesday, October 12, 2010

email

guilherme super viagem

caelum

Tuesday, October 12, 2010

email

guilherme super viagem

caelum

Tuesday, October 12, 2010

email

guilherme super viagem

caelum

kayak

Tuesday, October 12, 2010

email

guilherme super viagem

caelum

kayak

Tuesday, October 12, 2010

email

guilherme super viagem

caelum

kayak

Tuesday, October 12, 2010

Put your server to RESTleonard richardsons model

Tuesday, October 12, 2010

Server Maturity1 uri, 1 http verb

/services.do?action=install&...

Tuesday, October 12, 2010

Server Maturity1 uri, 1 http verb

/services.do?action=install&...

@Path("/services")public class Services {

  @GET  public Response services(    @QueryParam("action") String action) {

    ServiceFactory factory = new ServiceFactory();    Service service = factory.getServiceFor(action);    return service.execute();  }

}Tuesday, October 12, 2010

Server Maturity

public class InstallService {

  public Response execute() {    return Response.ok()             .type("application/xml")             .entity("<service>...</service>")             .build();  }

}

1 uri, 1 http verb

Tuesday, October 12, 2010

But?

Tuesday, October 12, 2010

1 uri, 1 http verb

/services.do?action=install&...

I know them all beforehand.

Tuesday, October 12, 2010

1 uri, 1 http verb

/services.do?action=install&...

Any change will break all our clients!

Tuesday, October 12, 2010

a priori knowledge

Tuesday, October 12, 2010

a priori knowledge=

Tuesday, October 12, 2010

a priori knowledge=

coupling++

Tuesday, October 12, 2010

Server MaturityMultiple uris, 1 http verb

/install?...

Tuesday, October 12, 2010

Server MaturityMultiple uris, 1 http verb

/install?...

@Path("/services")public class Services {

  @GET @Path("install")  public Response install() {    return new InstallService().execute();  }

  @GET @Path("uninstall")  public Response uninstall() {    return new UninstallService().execute();  }

Tuesday, October 12, 2010

but...

Tuesday, October 12, 2010

GET should not imply in undesireable effects

GET hell

Tuesday, October 12, 2010

GET could help us with cache!

POST hell

Tuesday, October 12, 2010

Server MaturityMultiple uris, multiple verbs

POST /cloudGET /cloud/1547437/softwarePOST /cloud/1547437/software

Tuesday, October 12, 2010

rails + restfulierubyonrails.org

Tuesday, October 12, 2010

rails + restfulieclass SoftwaresController < ApplicationController    acts_as_restfulie  respond_to :xml, :json    def create    @item = Item.create(params[:item])    respond_with @item, :status => :created  end    def show    @item = Item.find(params[:id])    respond_with @item  endend

rubyonrails.org

Tuesday, October 12, 2010

Vraptorvraptor.org/en

Tuesday, October 12, 2010

Vraptor

@Resourcepublic class SoftwareResource {

  public void install() {    Software software = SoftwareRepository.register (software);    response.created(software);  }

  public void uninstall() {    response.deleted(software);  }

}

vraptor.org/en

Tuesday, October 12, 2010

JAX-RS

@Path("/softwares")public class SoftwareResource {

  @POST @Consumes("application/xml")  public Response install(Software software) {    software = SoftwareRepository.register(software);    long id = software.getId();    URI uri = UriBuilder.fromPath("/softwares/" + id)                                       .build();    software.install();    return Response.created(uri).build();  }

Tuesday, October 12, 2010

JAX-RS

  @DELETE @Path("{id}")  public Response uninstall(@PathParam("id") Long id) {    Software software = SoftwareRepository.retrieve(id);    software.uninstall();    return Response.ok().build();  }

Tuesday, October 12, 2010

Uniform Interface++Resources++

Tuesday, October 12, 2010

Http verbs examplePOST creates

PUT replaces

PATCH updates

DELETE removes

GET retrieves

OPTIONS tells me what i can do

...

Tuesday, October 12, 2010

Is a Restful servicea cute CRUD?

Tuesday, October 12, 2010

yes

Tuesday, October 12, 2010

but there is more!

Tuesday, October 12, 2010

enter amazon.com

hypermedia

Tuesday, October 12, 2010

enter amazon.com

search (GET)

hypermedia

Tuesday, October 12, 2010

enter amazon.com

search (GET)

create a payment (POST)

hypermedia

Tuesday, October 12, 2010

enter amazon.com

search (GET)

create a payment (POST)

search (GET)

hypermedia

Tuesday, October 12, 2010

enter amazon.com

search (GET)

create a payment (POST)

search (GET)

create a basket (POST)

hypermedia

Tuesday, October 12, 2010

enter amazon.com

search (GET)

create a payment (POST)

search (GET)

create a basket (POST)

follow links

hypermedia

Tuesday, October 12, 2010

enter amazon.com

search (GET)

create a payment (POST)

search (GET)

create a basket (POST)

follow links

fill forms

hypermedia

Tuesday, October 12, 2010

Cloud API

GET /user/15 retrieves an user

Tuesday, October 12, 2010

Cloud API

GET /user/15 retrieves an user

follow GET machines accesses its machines

Tuesday, October 12, 2010

Cloud API

GET /user/15 retrieves an user

follow GET machines accesses its machines

follow POST self installs a new machine

Tuesday, October 12, 2010

Cloud API

GET /user/15 retrieves an user

follow GET machines accesses its machines

follow POST self installs a new machine

follow POST payment pay for it

Tuesday, October 12, 2010

$ curl http://localhost:9998/user/574 -iHTTP/1.1 200 OK...

retrieves an user

Tuesday, October 12, 2010

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><user>    <link rel="machines" href="/user/574/machines"/>    <name>guilherme silveira</name>    <website>www.caelum.com.br</site>   <link rel="payment" href="/payment/custom"/>    ...</user>

user

Tuesday, October 12, 2010

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><user>    <link rel="machines" href="/user/574/machines"/>    <name>guilherme silveira</name>    <website>www.caelum.com.br</site>   <link rel="payment" href="/payment/custom"/>    ...</user>

user

Tuesday, October 12, 2010

$ curl http://localhost:9998/user/574/machines -iHTTP/1.1 200 OKContent-Type: application/xml

maschine maschine maschine

Tuesday, October 12, 2010

maschine<?xml version="1.0" encoding="UTF-8" standalone="yes"?><machines xmlns:ns2="http://www.w3.org/2005/Atom">  <machine>    <ns2:link rel="self" href="/user/574/machines/1"/>    <ns2:link rel="software" href="/machines1/softwares"/>    <id>1</id>    <host>www.caelum.com.br</host>    <softwares>      <software>        <id>1234</id>        <ns2:link rel="self" href="/softwares/1234"/>      </software>    </softwares>  </machine></machines>

Tuesday, October 12, 2010

maschine<?xml version="1.0" encoding="UTF-8" standalone="yes"?><machines xmlns:ns2="http://www.w3.org/2005/Atom">  <machine>    <ns2:link rel="self" href="/user/574/machines/1"/>    <ns2:link rel="software" href="/machines1/softwares"/>    <id>1</id>    <host>www.caelum.com.br</host>    <softwares>      <software>        <id>1234</id>        <ns2:link rel="self" href="/softwares/1234"/>      </software>    </softwares>  </machine></machines>

Tuesday, October 12, 2010

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><user>    <link rel="machines" href="/user/574/machines"/>    <name>guilherme silveira</name>    <website>www.caelum.com.br</site>   <link rel="payment" href="/payment/custom"/>    ...</user>

payment

Tuesday, October 12, 2010

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><user>    <link rel="machines" href="/user/574/machines"/>    <name>guilherme silveira</name>    <website>www.caelum.com.br</site>   <link rel="payment" href="/payment/custom"/>    ...</user>

payment

Tuesday, October 12, 2010

#buthow?

Tuesday, October 12, 2010

Machine.java

@XmlRootElement@XmlType(propOrder= {"id", "host", "softwares", "links"})public class Machine {  private final all variables here;

  @XmlElement(name="link", namespace="http://www.w3.org/2005/Atom")  public List<Link> getLinks() {    return Arrays.asList(      Link.to("/machines/" + getId(), "self"),      Link.to("/machines/" + getId() + "/softwares", "softwares")    );  }

  @XmlElementWrapper(name="softwares")  @XmlElement(name="software")  public List<Software> getSoftwares() {    return softwares;  }

  public void install(Software software) {    getSoftwares().add(software);  }

  public void uninstall(Software software) {    getSoftwares().remove(software);  }

}

Tuesday, October 12, 2010

Machine.java

@XmlRootElement@XmlType(propOrder= {"id", "host", "softwares", "links"})public class Machine {  private final all variables here;

  @XmlElement(name="link", namespace="http://www.w3.org/2005/Atom")  public List<Link> getLinks() {    return Arrays.asList(      Link.to("/machines/" + getId(), "self"),      Link.to("/machines/" + getId() + "/softwares", "softwares")    );  }

  @XmlElementWrapper(name="softwares")  @XmlElement(name="software")  public List<Software> getSoftwares() {    return softwares;  }

  public void install(Software software) {    getSoftwares().add(software);  }

  public void uninstall(Software software) {    getSoftwares().remove(software);  }

}

Tuesday, October 12, 2010

@Path("/machines")public class MachineResource {

@Path("{id}/softwares") public SoftwareResource softwares(@PathParam("id") Long id) { Machine machine = new MachineRepository().retrieve(id); if (machine != null) { SoftwareResource softwareResource = new SoftwareResource(); softwareResource.setMachine(machine); return softwareResource; } throw new WebApplicationException(404); }

@POST @Consumes("application/xml") public Response create(Machine machine) { Long id = new MachineRepository().save(machine); return Response.created(UriBuilder.fromPath("/" + id).build()).build(); }

@GET @Path("{id}") @Produces("application/xml") public Machine show(@PathParam("id") Long id) { return new MachineRepository().retrieve(id); }

@GET @Produces("application/xml") public Machines list() { Machines machines = new Machines(); machines.setMachine(new MachineRepository().list()); return machines; }}

MachineResource

Tuesday, October 12, 2010

@Path("/machines")public class MachineResource {

@Path("{id}/softwares") public SoftwareResource softwares(@PathParam("id") Long id) { Machine machine = new MachineRepository().retrieve(id); if (machine != null) { SoftwareResource softwareResource = new SoftwareResource(); softwareResource.setMachine(machine); return softwareResource; } throw new WebApplicationException(404); }

@POST @Consumes("application/xml") public Response create(Machine machine) { Long id = new MachineRepository().save(machine); return Response.created(UriBuilder.fromPath("/" + id).build()).build(); }

@GET @Path("{id}") @Produces("application/xml") public Machine show(@PathParam("id") Long id) { return new MachineRepository().retrieve(id); }

@GET @Produces("application/xml") public Machines list() { Machines machines = new Machines(); machines.setMachine(new MachineRepository().list()); return machines; }}

MachineResource

Tuesday, October 12, 2010

Server Modelaccording toLeonard Richardson, 2008

one uri + one verb

Tuesday, October 12, 2010

Server Modelaccording toLeonard Richardson, 2008

one uri + one verb

Ugly

Tuesday, October 12, 2010

Server Modelaccording toLeonard Richardson, 2008

multipleuris

one uri + one verb

Tuesday, October 12, 2010

Server Modelaccording toLeonard Richardson, 2008

multipleuris

one uri + one verb

Less ugly

Tuesday, October 12, 2010

Server Modelaccording toLeonard Richardson, 2008

multipleverbs

multipleuris

one uri + one verb

Tuesday, October 12, 2010

Server Modelaccording toLeonard Richardson, 2008

multipleverbs

multipleuris

one uri + one verb

cute CRUD

Tuesday, October 12, 2010

Server Modelaccording toLeonard Richardson, 2008

multipleverbs

multipleuris

hypermedia

one uri + one verb

rest

Tuesday, October 12, 2010

JAX-RS wishlist

VRaptor and Restfulie

Tuesday, October 12, 2010

examplesvraptor.org/en

Tuesday, October 12, 2010

1. conventions?

@Path("/services")public class Services {

  @GET  public Response services(    @QueryParam("action") String action) {

    ServiceFactory factory = new ServiceFactory();    Service service = factory.getServiceFor(action);    return service.execute();  }

}Tuesday, October 12, 2010

Convention over Configuration

@Resourcepublic class Services { private final ServiceFactory factory; public Services(ServiceFactory factory) { this.factory = factory; }

public void services(String action) { factory.getServiceFor(action).execute(); }

}Tuesday, October 12, 2010

do you want to avoid copy+paste?

Tuesday, October 12, 2010

yes!

Tuesday, October 12, 2010

yes!

Tuesday, October 12, 2010

2. TDD: hard to test@Path("/products")public class Products {

  @GET  public Response create(    @QueryParam("what") String what) {

    // persists    return Response.ok()             .type("application/xml")             .entity("<product>...</product>")             .build();  }

}

coupled to the implementation

Tuesday, October 12, 2010

TDD: mock it

@Resourcepublic class Services { private final Response response; public Services(Response response) { this.response = response; }

public void services(String action) { response.getServiceFor(action).execute(); }

}

coupled to the interfacecouple--

Tuesday, October 12, 2010

TDD: mock it

@Resourcepublic class Services { private final Response response; public Services(Response response) { this.response = response; }

public void services(String action) { response.getServiceFor(action).execute(); }

}

coupled to the interfacecouple--

Tuesday, October 12, 2010

3. Content negotiation by hand

@Path("/softwares")public class SoftwareResource {

  @POST @Consumes("application/xml")  public Response install(Software software) {    software = SoftwareRepository.register(software);    long id = software.getId();    URI uri = UriBuilder.fromPath("/softwares/" + id)                                       .build(); software.install();    return Response.created(uri).build();  }

Tuesday, October 12, 2010

Let us do it for you.

@Resourcepublic class SoftwareResource {

@Post @Consumes  public void install(Software software) {    software = SoftwareRepository.register(software);    response.created(software);  }

}

Tuesday, October 12, 2010

Let us do it for you.

@Resourcepublic class SoftwareResource {

@Post @Consumes  public void install(Software software) {    software = SoftwareRepository.register(software);    response.created(software);  }

}

Tuesday, October 12, 2010

4. URI coupling

...

  @GET @Path("/softwares/{id}")  public Response install(@QueryParam("id") Software software) { // ...  }

writing the URI once

Tuesday, October 12, 2010

4. URI coupling

@Path("/softwares")public class SoftwareResource {

  @POST @Consumes("application/xml")  public Response install(Software software) {    software = SoftwareRepository.register(software);    long id = software.getId();    URI uri = UriBuilder.fromPath("/softwares/" + id)                                       .build(); software.install();    return Response.created(uri).build();  }

writing the URI again several times

Tuesday, October 12, 2010

4. URI coupling

@Path("/softwares")public class SoftwareResource {

  @POST @Consumes("application/xml")  public Response install(Software software) {    software = SoftwareRepository.register(software);    long id = software.getId();    URI uri = UriBuilder.fromPath("/softwares/" + id)                                       .build(); software.install();    return Response.created(uri).build();  }

code

Tuesday, October 12, 2010

ZERO uri replication

@Resourcepublic class SoftwareResource {

@Post @Consumes  public void install(Software software) {    // ...    response.use(SoftwareResource.class).show(software);  }

}

Tuesday, October 12, 2010

ZERO uri replication

@Resourcepublic class SoftwareResource {

@Post @Consumes  public void install(Software software) {    // ...    response.use(SoftwareResource.class).show(software);  }

}

Tuesday, October 12, 2010

@Path("/machines")public class MachineResource {

@Path("{id}/softwares") public SoftwareResource softwares(@PathParam("id") Long id) { Machine machine = new MachineRepository().retrieve(id); if (machine == null) { throw new WebApplicationException(404); } // ... }

}

5. Parameter list

Tuesday, October 12, 2010

Yes, we can do it.

@Resourcepublic class MachineResource {

@Post ("{m.id}/softwares") public SoftwareResource softwares(Machine m) { Machine machine = new MachineRepository().retrieve(m); // ... }

}

parameter converter chain of responsabilityTuesday, October 12, 2010

Yes, we can do it.

@Resourcepublic class MachineResource {

@Post ("{m.id}/softwares") public SoftwareResource softwares(Machine m) { Machine machine = new MachineRepository().retrieve(m); // ... }

}

parameter converter chain of responsabilityTuesday, October 12, 2010

examplerestfulie.caelumobjects.com

Tuesday, October 12, 2010

Response response = client.at ("http://localhost:9998/user/574").get();

6. Client internal DSLs

Tuesday, October 12, 2010

Response response = client.at ("http://localhost:9998/user/574").get();

User user = response.getResource();System.out.println("user: " + user.getName());

6. Client internal DSLs

Tuesday, October 12, 2010

User user = response.getResource();System.out.println("user: " + user.getName());

Link link = resource(user).getLink("machine");response = link.follow().post(new Machine());

Tuesday, October 12, 2010

Link link = resource(user).getLink("machine");response = link.follow().post(new Machine());

double amount = resource(user).refresh(). getAmountDue();

Tuesday, October 12, 2010

double amount = resource(user).refresh(). getAmountDue();

link = resource(user).getLink("payment");Payment payment = new Payment(amount);response = link.follow().post(payment);

Tuesday, October 12, 2010

System.out.println("payment completed");

link = resource(user).getLink("payment");Payment payment = new Payment(amount);response = link.follow().post(payment);

Tuesday, October 12, 2010

System.out.println("payment completed");

link = resource(user).getLink("payment");Payment payment = new Payment(amount);response = link.follow().post(payment);

i was looking for a DSL and i did not know it!

Tuesday, October 12, 2010

bottom up

microformato

mime type?

design by committe

controlled vocabulary

Tuesday, October 12, 2010

hypermídiaviabilizando a integração através da web

Tuesday, October 12, 2010

obrigado

Tuesday, October 12, 2010

code samples

Lucas Cavalcanti(java server)@lucascs

Anderson Leite (ruby)@anderson_leite

Tuesday, October 12, 2010

Further reading

Tuesday, October 12, 2010

Roy Fielding dissertation

Further reading

Tuesday, October 12, 2010

Roy Fielding dissertation

Rest in Practice, Jim Webber and others

Further reading

Tuesday, October 12, 2010

Roy Fielding dissertation

Rest in Practice, Jim Webber and others

Restful Webservices Cookbook, Subbu Allamaraju

Further reading

Tuesday, October 12, 2010

Roy Fielding dissertation

Rest in Practice, Jim Webber and others

Restful Webservices Cookbook, Subbu Allamaraju

Restful Web Services, Richardson and Ruby

Further reading

Tuesday, October 12, 2010

Roy Fielding dissertation

Rest in Practice, Jim Webber and others

Restful Webservices Cookbook, Subbu Allamaraju

Restful Web Services, Richardson and Ruby

JAX-RS specification

Further reading

Tuesday, October 12, 2010

Roy Fielding dissertation

Rest in Practice, Jim Webber and others

Restful Webservices Cookbook, Subbu Allamaraju

Restful Web Services, Richardson and Ruby

JAX-RS specification

Infoq articles on REST

Further reading

Tuesday, October 12, 2010

Roy Fielding dissertation

Rest in Practice, Jim Webber and others

Restful Webservices Cookbook, Subbu Allamaraju

Restful Web Services, Richardson and Ruby

JAX-RS specification

Infoq articles on REST

Restfulie guide

Further reading

Tuesday, October 12, 2010

Interviews and Presentations

Tuesday, October 12, 2010

Stefan Tilkov interview on InfoQ

Interviews and Presentations

Tuesday, October 12, 2010

Stefan Tilkov interview on InfoQ

http://bit.ly/9RUXKL

Interviews and Presentations

Tuesday, October 12, 2010

Stefan Tilkov interview on InfoQ

http://bit.ly/9RUXKL

Leonard Richardson’s presentation at QCon

Interviews and Presentations

Tuesday, October 12, 2010

Stefan Tilkov interview on InfoQ

http://bit.ly/9RUXKL

Leonard Richardson’s presentation at QCon

http://bit.ly/dj2W66

Interviews and Presentations

Tuesday, October 12, 2010

Stefan Tilkov interview on InfoQ

http://bit.ly/9RUXKL

Leonard Richardson’s presentation at QCon

http://bit.ly/dj2W66

Martin Fowler on REST

Interviews and Presentations

Tuesday, October 12, 2010

Stefan Tilkov interview on InfoQ

http://bit.ly/9RUXKL

Leonard Richardson’s presentation at QCon

http://bit.ly/dj2W66

Martin Fowler on REST

http://bit.ly/bx61ci

Interviews and Presentations

Tuesday, October 12, 2010

Interviews and Presentations

Tuesday, October 12, 2010

Ian Robinson and Jim Webber interview

Interviews and Presentations

Tuesday, October 12, 2010

Ian Robinson and Jim Webber interview

http://bit.ly/aEuzj3

Interviews and Presentations

Tuesday, October 12, 2010

Ian Robinson and Jim Webber interview

http://bit.ly/aEuzj3

Jan Algermissen classification

Interviews and Presentations

Tuesday, October 12, 2010

Ian Robinson and Jim Webber interview

http://bit.ly/aEuzj3

Jan Algermissen classification

http://bit.ly/cycFBF

Interviews and Presentations

Tuesday, October 12, 2010

Ian Robinson and Jim Webber interview

http://bit.ly/aEuzj3

Jan Algermissen classification

http://bit.ly/cycFBF

Guilherme Silveira on REST clients

Interviews and Presentations

Tuesday, October 12, 2010

Ian Robinson and Jim Webber interview

http://bit.ly/aEuzj3

Jan Algermissen classification

http://bit.ly/cycFBF

Guilherme Silveira on REST clients

http://bit.ly/aHCglv

Interviews and Presentations

Tuesday, October 12, 2010

code samples

Tuesday, October 12, 2010

JAX-RS

code samples

Tuesday, October 12, 2010

JAX-RS

http://jcp.org/en/jsr/detail?id=311

code samples

Tuesday, October 12, 2010

JAX-RS

http://jcp.org/en/jsr/detail?id=311

Rails

code samples

Tuesday, October 12, 2010

JAX-RS

http://jcp.org/en/jsr/detail?id=311

Rails

http://rubyonrails.org

code samples

Tuesday, October 12, 2010

JAX-RS

http://jcp.org/en/jsr/detail?id=311

Rails

http://rubyonrails.org

Restfulie

code samples

Tuesday, October 12, 2010

JAX-RS

http://jcp.org/en/jsr/detail?id=311

Rails

http://rubyonrails.org

Restfulie

http://restfulie.caelumobjects.com

code samples

Tuesday, October 12, 2010

JAX-RS

http://jcp.org/en/jsr/detail?id=311

Rails

http://rubyonrails.org

Restfulie

http://restfulie.caelumobjects.com

VRaptor

code samples

Tuesday, October 12, 2010

JAX-RS

http://jcp.org/en/jsr/detail?id=311

Rails

http://rubyonrails.org

Restfulie

http://restfulie.caelumobjects.com

VRaptor

http://vraptor.org/en

code samples

Tuesday, October 12, 2010