SlideShare une entreprise Scribd logo
1  sur  218
Télécharger pour lire hors ligne
Arquitetura: chega de
                             mesmice
                             Guilherme Silveira




Tuesday, October 12, 2010
Guilherme Silveira
                            guilherme.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 Silveira
                            guilherme.silveira@caelum.com.br




  2002 guj.com.br
  2003 vraptor
  2004 caelum.com.br
       xp, xstream
  2006 scrum
  2009 restfulie, lean
  2010 tectura.com.br
Tuesday, October 12, 2010
bank.com                 calendar.com




       travel.com           company.com
Tuesday, October 12, 2010
CORBA
                       heaven?



Tuesday, October 12, 2010
EJB
                            heaven?



Tuesday, October 12, 2010
SOAP
                            heaven?




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 Web


                                   Services




Tuesday, October 12, 2010
Restful Web

               create a saas account

                                       Services




Tuesday, October 12, 2010
Restful Web

               create a saas account


                            freeze account
                                             Services




Tuesday, October 12, 2010
Restful Web

               create a saas account


                            freeze account
                                             Services

                     reactivate account




Tuesday, October 12, 2010
Web




                   Restful         Services
Tuesday, October 12, 2010
Web
                             http




                   Restful          Services
Tuesday, October 12, 2010
Web
                              http

                             port 80




                   Restful             Services
Tuesday, October 12, 2010
Web
                                 http

                               port 80


                            firewall heaven


                   Restful               Services
Tuesday, October 12, 2010
Web Services


                 Restful




Tuesday, October 12, 2010
Web Services

                               xml, json
                 Restful




Tuesday, October 12, 2010
Web Services

                                xml, json
                 Restful
                               get, post, ...




Tuesday, October 12, 2010
Restful Web Services
                                    as of 2009




                            But what about Hypermidia?
                              What about consumers?




Tuesday, October 12, 2010
Restful Web Services
                                    as of 2009




                            But what about Hypermidia?
                              What about consumers?
                             There is much more!


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++

                                           unrest
                                            pay


                                   unresttrips.com

                      guilherme




Tuesday, October 12, 2010
service locator when integrating:
                                        coupling++

                                           unrest
                                            pay


                                   unresttrips.com

                      guilherme




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--

                                          restrips
                                            pay

                                    resttrips.com


                      guilherme




                                          paysite.com


Tuesday, October 12, 2010
dependency injection when integrating:

                                         coupling--

                                          restrips
                                            pay

                                    resttrips.com


                      guilherme




                                          paysite.com


Tuesday, October 12, 2010
trip = resource
                                    http://kayak.com/f/574XR4




                            payment = resource
                                    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




Tuesday, October 12, 2010
                             Bilu bilu
resttrips.com: sharing a trip


            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);




Tuesday, October 12, 2010
resttrips.com: sharing a trip


            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);




Tuesday, October 12, 2010
resttrips.com: sharing a trip


            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);




Tuesday, October 12, 2010
resttrips.com: sharing a trip


            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);




Tuesday, October 12, 2010
calendar: integrating my systems


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

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




Tuesday, October 12, 2010
calendar: integrating my systems


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

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




Tuesday, October 12, 2010
calendar: more examples



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




Tuesday, October 12, 2010
so what?




Tuesday, October 12, 2010
so what?




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

Tuesday, October 12, 2010
so what?



                                                                  r at e!
                                                           i nt eg
                                                   us e,
                                           ju st
                                  o n ’t
                                d
                            Any update on the flight ==> reflects here
                            Any update on the hotel ==> reflects here
                            Any update on the meeting ==> reflects here

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 flight
                            Remove ==> Cancels the reservation
                            Remove ==> Emails your coworkers

Tuesday, October 12, 2010
so what? that was just keeping an URI.



                                                             ro l!
                                                        co nt
                                              a li ze
                                         en tr
                                    no tc
                               do
                            Remove ==> Cancels the flight
                            Remove ==> Cancels the reservation
                            Remove ==> Emails your coworkers

Tuesday, October 12, 2010
integration over the web




     INTEGRATION is DECENTRALIZING the CONTROL
               delegating 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 flight
                            Remove ==> Cancels the reservation
                            Remove ==> Emails your coworkers

Tuesday, October 12, 2010
so what? that was just keeping an URI.




                                                          a t?
                                                  fo rm
                                          hi ch
                                    bu tw

                            Remove ==> Cancels the flight
                            Remove ==> Cancels the reservation
                            Remove ==> Emails your coworkers

Tuesday, October 12, 2010
mas qual o formato do
                            pagamento 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?




                                                   lh a!
                                                  fi
                                            in ha
                                      é m
                               n ão



Tuesday, October 12, 2010
conteúdo sem semântica
                     nã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?



                                                              nk s!
                                                         er li
                                                      hyp
                                              w ith
                                        ats
                                   fo rm
                             ic ro
                            m

                            micro formats, media types, rdf etc

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 voo
               def voos_de(site)
                 base = Restfulie.at(site).get
                 voos = base.link("opensearch").get.fill("flight").with(:from =>
               "GRU", :to => "JFK").get
               end

               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 REST
                            leonard richardsons model




Tuesday, October 12, 2010
Server Maturity
                              1 uri, 1 http verb

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




Tuesday, October 12, 2010
Server Maturity
                              1 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
                              1 uri, 1 http verb


           public class InstallService {

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

           }




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 Maturity
                            Multiple uris, 1 http verb

     /install?...




Tuesday, October 12, 2010
Server Maturity
                            Multiple 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 hell


                            GET should not imply in
                              undesireable effects




Tuesday, October 12, 2010
POST hell


                            GET could help us with
                                    cache!




Tuesday, October 12, 2010
Server Maturity
                              Multiple uris, multiple verbs




                                     POST /cloud
                             GET /cloud/1547437/software
                            POST /cloud/1547437/software




Tuesday, October 12, 2010
rails + restfulie
                              rubyonrails.org




Tuesday, October 12, 2010
rails + restfulie
                              rubyonrails.org
 class 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
   end
 end


Tuesday, October 12, 2010
Vraptor
                            vraptor.org/en




Tuesday, October 12, 2010
Vraptor
                            vraptor.org/en
 @Resource
 public class SoftwareResource {

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

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

 }


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 example
                      POST creates

                      PUT replaces

                      PATCH updates

                      DELETE removes

                      GET retrieves

                      OPTIONS tells me what i can do

                      ...


Tuesday, October 12, 2010
Is a Restful service
                               a cute CRUD?



Tuesday, October 12, 2010
yes

Tuesday, October 12, 2010
but there is more!


Tuesday, October 12, 2010
hypermedia
                              enter amazon.com




Tuesday, October 12, 2010
hypermedia
                              enter amazon.com

                                search (GET)




Tuesday, October 12, 2010
hypermedia
                                enter amazon.com

                                  search (GET)




                             create a payment (POST)



Tuesday, October 12, 2010
hypermedia
                                enter amazon.com

                                  search (GET)

                                  search (GET)



                             create a payment (POST)



Tuesday, October 12, 2010
hypermedia
                                enter amazon.com

                                  search (GET)

                                  search (GET)

                              create a basket (POST)

                             create a payment (POST)



Tuesday, October 12, 2010
hypermedia
                                enter amazon.com       follow links


                                  search (GET)

                                  search (GET)

                              create a basket (POST)

                             create a payment (POST)



Tuesday, October 12, 2010
hypermedia
                                enter amazon.com       follow links


                                  search (GET)

                                  search (GET)
                                                        fill forms
                              create a basket (POST)

                             create a payment (POST)



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
retrieves an user


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




Tuesday, October 12, 2010
user

  <?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>




Tuesday, October 12, 2010
user

  <?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>




Tuesday, October 12, 2010
maschine maschine maschine



        $ curl http://localhost:9998/user/574/machines -i
        HTTP/1.1 200 OK
        Content-Type: application/xml




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
payment


     <?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>




Tuesday, October 12, 2010
payment


     <?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>




Tuesday, October 12, 2010
#buthow?



Tuesday, October 12, 2010
@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);
       }

     }                                              Machine.java
Tuesday, October 12, 2010
@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);
       }

     }                                              Machine.java
Tuesday, October 12, 2010
@Path("/machines")
  public class MachineResource {          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;
Tuesday, October 12, 2010
@Path("/machines")
  public class MachineResource {          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;
Tuesday, October 12, 2010
Server Model
       according to
       Leonard Richardson, 2008




                                  one uri + one verb

Tuesday, October 12, 2010
Server Model
       according to
       Leonard Richardson, 2008




                                      Ugly
                                  one uri + one verb

Tuesday, October 12, 2010
Server Model
       according to
       Leonard Richardson, 2008




                                  multiple
                                   uris



                                   one uri + one verb

Tuesday, October 12, 2010
Server Model
       according to
       Leonard Richardson, 2008



                                             Less ugly
                                  multiple
                                   uris



                                   one uri + one verb

Tuesday, October 12, 2010
Server Model
       according to
       Leonard Richardson, 2008


                                              multiple
                                               verbs
                                  multiple
                                   uris



                                   one uri + one verb

Tuesday, October 12, 2010
Server Model
       according to
       Leonard Richardson, 2008
                                  cute CRUD
                                              multiple
                                               verbs
                                  multiple
                                   uris



                                   one uri + one verb

Tuesday, October 12, 2010
Server Model                       rest
       according to
       Leonard Richardson, 2008        hypermedia


                                              multiple
                                               verbs
                                  multiple
                                   uris



                                   one uri + one verb

Tuesday, October 12, 2010
JAX-RS wishlist

                              VRaptor and Restfulie




Tuesday, October 12, 2010
examples
                            vraptor.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


        @Resource
        public 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 {
                                         coupled to the
        @GET                            implementation
        public Response create(
          @QueryParam("what") String what) {

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

      }

Tuesday, October 12, 2010
TDD: mock it
                                         coupled to the interface
                                                couple--

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

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

        }
Tuesday, October 12, 2010
TDD: mock it
                                         coupled to the interface
                                                couple--

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

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

        }
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.


 @Resource
 public 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.


 @Resource
 public class SoftwareResource {

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

 }




Tuesday, October 12, 2010
4. URI coupling

                                        writing the URI once


  ...

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




Tuesday, October 12, 2010
4. URI coupling
                                        writing the URI again
                                             several times
  @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
4. URI coupling
                                              code
  @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
ZERO uri replication


 @Resource
 public class SoftwareResource {

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

 }




Tuesday, October 12, 2010
ZERO uri replication


 @Resource
 public class SoftwareResource {

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

 }




Tuesday, October 12, 2010
5. Parameter list


                @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);
                    }
                    // ...
                
 }


                }




Tuesday, October 12, 2010
Yes, we can do it.


 @Resource
 public class MachineResource {

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

 }



                            parameter converter chain of responsability
Tuesday, October 12, 2010
Yes, we can do it.


 @Resource
 public class MachineResource {

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

 }



                            parameter converter chain of responsability
Tuesday, October 12, 2010
example
          restfulie.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
link = resource(user).getLink("payment");
                        Payment payment = new Payment(amount);
                        response = link.follow().post(payment);

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




Tuesday, October 12, 2010
link = resource(user).getLink("payment");
                        Payment payment = new Payment(amount);
                        response = link.follow().post(payment);

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




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

Tuesday, October 12, 2010
bottom up
                             design by committe
                                 mime type?
                               microformato
                            controlled vocabulary


Tuesday, October 12, 2010
hypermídia
                            viabilizando 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
Further reading
         Roy Fielding dissertation




Tuesday, October 12, 2010
Further reading
         Roy Fielding dissertation

         Rest in Practice, Jim Webber and others




Tuesday, October 12, 2010
Further reading
         Roy Fielding dissertation

         Rest in Practice, Jim Webber and others

         Restful Webservices Cookbook, Subbu Allamaraju




Tuesday, October 12, 2010
Further reading
         Roy Fielding dissertation

         Rest in Practice, Jim Webber and others

         Restful Webservices Cookbook, Subbu Allamaraju

         Restful Web Services, Richardson and Ruby




Tuesday, October 12, 2010
Further reading
         Roy Fielding dissertation

         Rest in Practice, Jim Webber and others

         Restful Webservices Cookbook, Subbu Allamaraju

         Restful Web Services, Richardson and Ruby

         JAX-RS specification




Tuesday, October 12, 2010
Further reading
         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



Tuesday, October 12, 2010
Further reading
         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

Tuesday, October 12, 2010
Interviews and
                             Presentations




Tuesday, October 12, 2010
Interviews and
                             Presentations
         Stefan Tilkov interview on InfoQ




Tuesday, October 12, 2010
Interviews and
                             Presentations
         Stefan Tilkov interview on InfoQ

               http://bit.ly/9RUXKL




Tuesday, October 12, 2010
Interviews and
                             Presentations
         Stefan Tilkov interview on InfoQ

               http://bit.ly/9RUXKL

         Leonard Richardson’s presentation at QCon




Tuesday, October 12, 2010
Interviews and
                             Presentations
         Stefan Tilkov interview on InfoQ

               http://bit.ly/9RUXKL

         Leonard Richardson’s presentation at QCon

               http://bit.ly/dj2W66




Tuesday, October 12, 2010
Interviews and
                             Presentations
         Stefan Tilkov interview on InfoQ

               http://bit.ly/9RUXKL

         Leonard Richardson’s presentation at QCon

               http://bit.ly/dj2W66

         Martin Fowler on REST




Tuesday, October 12, 2010
Interviews and
                             Presentations
         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


Tuesday, October 12, 2010
Interviews and
                             Presentations




Tuesday, October 12, 2010
Interviews and
                             Presentations
         Ian Robinson and Jim Webber interview




Tuesday, October 12, 2010
Interviews and
                             Presentations
         Ian Robinson and Jim Webber interview

               http://bit.ly/aEuzj3




Tuesday, October 12, 2010
Interviews and
                             Presentations
         Ian Robinson and Jim Webber interview

               http://bit.ly/aEuzj3

         Jan Algermissen classification




Tuesday, October 12, 2010
Interviews and
                             Presentations
         Ian Robinson and Jim Webber interview

               http://bit.ly/aEuzj3

         Jan Algermissen classification

               http://bit.ly/cycFBF




Tuesday, October 12, 2010
Interviews and
                             Presentations
         Ian Robinson and Jim Webber interview

               http://bit.ly/aEuzj3

         Jan Algermissen classification

               http://bit.ly/cycFBF

         Guilherme Silveira on REST clients




Tuesday, October 12, 2010
Interviews and
                             Presentations
         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


Tuesday, October 12, 2010
code samples




Tuesday, October 12, 2010
code samples
         JAX-RS




Tuesday, October 12, 2010
code samples
         JAX-RS

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




Tuesday, October 12, 2010
code samples
         JAX-RS

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

         Rails




Tuesday, October 12, 2010
code samples
         JAX-RS

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

         Rails

               http://rubyonrails.org




Tuesday, October 12, 2010
code samples
         JAX-RS

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

         Rails

               http://rubyonrails.org

         Restfulie




Tuesday, October 12, 2010
code samples
         JAX-RS

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

         Rails

               http://rubyonrails.org

         Restfulie

               http://restfulie.caelumobjects.com




Tuesday, October 12, 2010
code samples
         JAX-RS

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

         Rails

               http://rubyonrails.org

         Restfulie

               http://restfulie.caelumobjects.com

         VRaptor



Tuesday, October 12, 2010
code samples
         JAX-RS

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

         Rails

               http://rubyonrails.org

         Restfulie

               http://restfulie.caelumobjects.com

         VRaptor

               http://vraptor.org/en
Tuesday, October 12, 2010

Contenu connexe

En vedette

En vedette (18)

Analise de terrenos
Analise de terrenosAnalise de terrenos
Analise de terrenos
 
Devise
DeviseDevise
Devise
 
Rest clients
Rest clientsRest clients
Rest clients
 
Software de qualidade e qualidade de código
Software de qualidade e qualidade de códigoSoftware de qualidade e qualidade de código
Software de qualidade e qualidade de código
 
noSql + rest: Arquitetura Contemporanea
noSql + rest: Arquitetura ContemporaneanoSql + rest: Arquitetura Contemporanea
noSql + rest: Arquitetura Contemporanea
 
SPDY
SPDYSPDY
SPDY
 
Agile performance testing
Agile performance testingAgile performance testing
Agile performance testing
 
Brief Introduction to REST
Brief Introduction to RESTBrief Introduction to REST
Brief Introduction to REST
 
Rest workflows
Rest workflowsRest workflows
Rest workflows
 
Put your client and server to rest - Javaone
Put your client and server to rest - JavaonePut your client and server to rest - Javaone
Put your client and server to rest - Javaone
 
Rest clients
Rest clientsRest clients
Rest clients
 
Rest @ Qcon 2010
Rest @ Qcon 2010Rest @ Qcon 2010
Rest @ Qcon 2010
 
Arquitetura: chega de mesmice
Arquitetura: chega de mesmiceArquitetura: chega de mesmice
Arquitetura: chega de mesmice
 
Proposta de Parque Linear
Proposta de Parque LinearProposta de Parque Linear
Proposta de Parque Linear
 
REST: Hypermidia e Cache - DNAD 2011
REST: Hypermidia e Cache - DNAD 2011REST: Hypermidia e Cache - DNAD 2011
REST: Hypermidia e Cache - DNAD 2011
 
O grandiosismo dos loucos - Agile Brazil 2011, Cecilia Fernandes e Guilherme ...
O grandiosismo dos loucos - Agile Brazil 2011, Cecilia Fernandes e Guilherme ...O grandiosismo dos loucos - Agile Brazil 2011, Cecilia Fernandes e Guilherme ...
O grandiosismo dos loucos - Agile Brazil 2011, Cecilia Fernandes e Guilherme ...
 
Depois de Scrum e XP: não pare de aprender, não pare de inovar
Depois de Scrum e XP: não pare de aprender, não pare de inovarDepois de Scrum e XP: não pare de aprender, não pare de inovar
Depois de Scrum e XP: não pare de aprender, não pare de inovar
 
Using the web for real
Using the web for realUsing the web for real
Using the web for real
 

Similaire à Arquitetura: chega de mesmice

We're not designing posters, here!
We're not designing posters, here!We're not designing posters, here!
We're not designing posters, here!André Luís
 
Opening up the Social Web - Standards that are bridging the Islands
Opening up the Social Web - Standards that are bridging the Islands Opening up the Social Web - Standards that are bridging the Islands
Opening up the Social Web - Standards that are bridging the Islands Bastian Hofmann
 
Sencha Touch beta — Amazing Mobile Web Apps with HTML5, CSS3 & JavaScript
Sencha Touch beta — Amazing Mobile Web Apps with HTML5, CSS3 & JavaScriptSencha Touch beta — Amazing Mobile Web Apps with HTML5, CSS3 & JavaScript
Sencha Touch beta — Amazing Mobile Web Apps with HTML5, CSS3 & JavaScriptDavid Kaneda
 
"Introduction Open Graph and Facebook Platform" - Facebook Developer Garage ...
"Introduction Open Graph and Facebook Platform" -  Facebook Developer Garage ..."Introduction Open Graph and Facebook Platform" -  Facebook Developer Garage ...
"Introduction Open Graph and Facebook Platform" - Facebook Developer Garage ...Vijay Rayapati
 
OpenStack Summit, A Community of Service Providers
OpenStack Summit, A Community of Service ProvidersOpenStack Summit, A Community of Service Providers
OpenStack Summit, A Community of Service ProvidersAndrew Shafer
 
Qconsp domesticando dragoes com soluções escaláveis
Qconsp   domesticando dragoes com soluções escaláveisQconsp   domesticando dragoes com soluções escaláveis
Qconsp domesticando dragoes com soluções escaláveisBruno Oliveira
 
Flex além do browser - Lightning talk qcon
Flex além do browser - Lightning talk qcon Flex além do browser - Lightning talk qcon
Flex além do browser - Lightning talk qcon David Paniz
 
Progressive Advancement, by way of progressive enhancement
Progressive Advancement, by way of progressive enhancementProgressive Advancement, by way of progressive enhancement
Progressive Advancement, by way of progressive enhancementPaul Irish
 

Similaire à Arquitetura: chega de mesmice (9)

We're not designing posters, here!
We're not designing posters, here!We're not designing posters, here!
We're not designing posters, here!
 
Opening up the Social Web - Standards that are bridging the Islands
Opening up the Social Web - Standards that are bridging the Islands Opening up the Social Web - Standards that are bridging the Islands
Opening up the Social Web - Standards that are bridging the Islands
 
Sencha Touch beta — Amazing Mobile Web Apps with HTML5, CSS3 & JavaScript
Sencha Touch beta — Amazing Mobile Web Apps with HTML5, CSS3 & JavaScriptSencha Touch beta — Amazing Mobile Web Apps with HTML5, CSS3 & JavaScript
Sencha Touch beta — Amazing Mobile Web Apps with HTML5, CSS3 & JavaScript
 
"Introduction Open Graph and Facebook Platform" - Facebook Developer Garage ...
"Introduction Open Graph and Facebook Platform" -  Facebook Developer Garage ..."Introduction Open Graph and Facebook Platform" -  Facebook Developer Garage ...
"Introduction Open Graph and Facebook Platform" - Facebook Developer Garage ...
 
OpenStack Summit, A Community of Service Providers
OpenStack Summit, A Community of Service ProvidersOpenStack Summit, A Community of Service Providers
OpenStack Summit, A Community of Service Providers
 
Qconsp domesticando dragoes com soluções escaláveis
Qconsp   domesticando dragoes com soluções escaláveisQconsp   domesticando dragoes com soluções escaláveis
Qconsp domesticando dragoes com soluções escaláveis
 
Flex além do browser - Lightning talk qcon
Flex além do browser - Lightning talk qcon Flex além do browser - Lightning talk qcon
Flex além do browser - Lightning talk qcon
 
Progressive Advancement, by way of progressive enhancement
Progressive Advancement, by way of progressive enhancementProgressive Advancement, by way of progressive enhancement
Progressive Advancement, by way of progressive enhancement
 
CSS Bloat!
CSS Bloat!CSS Bloat!
CSS Bloat!
 

Plus de Guilherme Silveira

Equipes ágeis em 2012 - Lições aprendidas
Equipes ágeis em 2012 - Lições aprendidasEquipes ágeis em 2012 - Lições aprendidas
Equipes ágeis em 2012 - Lições aprendidasGuilherme Silveira
 
Introducao a machine learning na educacao
Introducao a machine learning na educacaoIntroducao a machine learning na educacao
Introducao a machine learning na educacaoGuilherme Silveira
 
Crie seu sistema REST com JAX-RS e o futuro
Crie seu sistema REST com JAX-RS e o futuroCrie seu sistema REST com JAX-RS e o futuro
Crie seu sistema REST com JAX-RS e o futuroGuilherme Silveira
 
Deploy continuo, integraçao continua não basta
Deploy continuo, integraçao continua não bastaDeploy continuo, integraçao continua não basta
Deploy continuo, integraçao continua não bastaGuilherme Silveira
 
Caelum 2010 - Rest Arquitetura Irreponsavel?
Caelum 2010 - Rest Arquitetura Irreponsavel?Caelum 2010 - Rest Arquitetura Irreponsavel?
Caelum 2010 - Rest Arquitetura Irreponsavel?Guilherme Silveira
 
Caelum 2009 Rest Ao Restful - CEJUG 2009
Caelum 2009   Rest Ao Restful - CEJUG 2009Caelum 2009   Rest Ao Restful - CEJUG 2009
Caelum 2009 Rest Ao Restful - CEJUG 2009Guilherme Silveira
 

Plus de Guilherme Silveira (11)

Equipes ágeis em 2012 - Lições aprendidas
Equipes ágeis em 2012 - Lições aprendidasEquipes ágeis em 2012 - Lições aprendidas
Equipes ágeis em 2012 - Lições aprendidas
 
Introducao a machine learning na educacao
Introducao a machine learning na educacaoIntroducao a machine learning na educacao
Introducao a machine learning na educacao
 
Crie seu sistema REST com JAX-RS e o futuro
Crie seu sistema REST com JAX-RS e o futuroCrie seu sistema REST com JAX-RS e o futuro
Crie seu sistema REST com JAX-RS e o futuro
 
Arquitetura: chega de mesmice
Arquitetura: chega de mesmiceArquitetura: chega de mesmice
Arquitetura: chega de mesmice
 
Arquitetura chega de mesmice
Arquitetura  chega de mesmiceArquitetura  chega de mesmice
Arquitetura chega de mesmice
 
Rest clients
Rest clientsRest clients
Rest clients
 
Um produto por semana
Um produto por semanaUm produto por semana
Um produto por semana
 
Deploy continuo, integraçao continua não basta
Deploy continuo, integraçao continua não bastaDeploy continuo, integraçao continua não basta
Deploy continuo, integraçao continua não basta
 
Caelum 2010 - Rest Arquitetura Irreponsavel?
Caelum 2010 - Rest Arquitetura Irreponsavel?Caelum 2010 - Rest Arquitetura Irreponsavel?
Caelum 2010 - Rest Arquitetura Irreponsavel?
 
REST in Practice
REST in PracticeREST in Practice
REST in Practice
 
Caelum 2009 Rest Ao Restful - CEJUG 2009
Caelum 2009   Rest Ao Restful - CEJUG 2009Caelum 2009   Rest Ao Restful - CEJUG 2009
Caelum 2009 Rest Ao Restful - CEJUG 2009
 

Dernier

Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 

Dernier (20)

Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 

Arquitetura: chega de mesmice

  • 1. Arquitetura: chega de mesmice Guilherme Silveira Tuesday, October 12, 2010
  • 2. Guilherme Silveira guilherme.silveira@caelum.com.br Tuesday, October 12, 2010
  • 8. Guilherme Silveira guilherme.silveira@caelum.com.br 2002 guj.com.br 2003 vraptor 2004 caelum.com.br xp, xstream 2006 scrum 2009 restfulie, lean 2010 tectura.com.br Tuesday, October 12, 2010
  • 9. bank.com calendar.com travel.com company.com Tuesday, October 12, 2010
  • 10. CORBA heaven? Tuesday, October 12, 2010
  • 11. EJB heaven? Tuesday, October 12, 2010
  • 12. SOAP heaven? Tuesday, October 12, 2010
  • 13. what is REST? Tuesday, October 12, 2010
  • 14. what is the future of integration over the web? Tuesday, October 12, 2010
  • 15. what was REST? Tuesday, October 12, 2010
  • 16. Restful Web Services Tuesday, October 12, 2010
  • 17. Restful Web create a saas account Services Tuesday, October 12, 2010
  • 18. Restful Web create a saas account freeze account Services Tuesday, October 12, 2010
  • 19. Restful Web create a saas account freeze account Services reactivate account Tuesday, October 12, 2010
  • 20. Web Restful Services Tuesday, October 12, 2010
  • 21. Web http Restful Services Tuesday, October 12, 2010
  • 22. Web http port 80 Restful Services Tuesday, October 12, 2010
  • 23. Web http port 80 firewall heaven Restful Services Tuesday, October 12, 2010
  • 24. Web Services Restful Tuesday, October 12, 2010
  • 25. Web Services xml, json Restful Tuesday, October 12, 2010
  • 26. Web Services xml, json Restful get, post, ... Tuesday, October 12, 2010
  • 27. Restful Web Services as of 2009 But what about Hypermidia? What about consumers? Tuesday, October 12, 2010
  • 28. Restful Web Services as of 2009 But what about Hypermidia? What about consumers? There is much more! Tuesday, October 12, 2010
  • 29. 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
  • 30. service locator when integrating: coupling++ unrest pay unresttrips.com guilherme Tuesday, October 12, 2010
  • 31. service locator when integrating: coupling++ unrest pay unresttrips.com guilherme Tuesday, October 12, 2010
  • 32. 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
  • 33. 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
  • 34. 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
  • 35. 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
  • 36. 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
  • 37. 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
  • 38. dependency injection when integrating: coupling-- restrips pay resttrips.com guilherme paysite.com Tuesday, October 12, 2010
  • 39. dependency injection when integrating: coupling-- restrips pay resttrips.com guilherme paysite.com Tuesday, October 12, 2010
  • 40. trip = resource http://kayak.com/f/574XR4 payment = resource any_uri_unknown_at_compile_time Tuesday, October 12, 2010
  • 45. não viajo sozinho Tuesday, October 12, 2010
  • 46. meu amigo @sergio_caelum Tuesday, October 12, 2010
  • 47. meu amigo @sergio_caelum Tuesday, October 12, 2010 Bilu bilu
  • 48. resttrips.com: sharing a trip 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); Tuesday, October 12, 2010
  • 49. resttrips.com: sharing a trip 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); Tuesday, October 12, 2010
  • 50. resttrips.com: sharing a trip 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); Tuesday, October 12, 2010
  • 51. resttrips.com: sharing a trip 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); Tuesday, October 12, 2010
  • 52. calendar: integrating my systems myself = Client.at('http://users.calendar.com') .with(auth).get(); myself.link("calendar").patch(flight.link("self")); Tuesday, October 12, 2010
  • 53. calendar: integrating my systems myself = Client.at('http://users.calendar.com') .with(auth).get(); myself.link("calendar").patch(flight.link("self")); Tuesday, October 12, 2010
  • 54. calendar: more examples me.link("calendar").patch(link_to_birthday_list) me.link("calendar").patch(link_to_hotel_reservation) me.link("calendar").patch(link_to_trip_details) Tuesday, October 12, 2010
  • 56. so what? Any update on the flight ==> reflects here Any update on the hotel ==> reflects here Any update on the meeting ==> reflects here Tuesday, October 12, 2010
  • 57. so what? r at e! i nt eg us e, ju st o n ’t d Any update on the flight ==> reflects here Any update on the hotel ==> reflects here Any update on the meeting ==> reflects here Tuesday, October 12, 2010
  • 58. so what? that was just keeping an URI. Tuesday, October 12, 2010
  • 59. so what? that was just keeping an URI. Remove ==> Cancels the flight Remove ==> Cancels the reservation Remove ==> Emails your coworkers Tuesday, October 12, 2010
  • 60. so what? that was just keeping an URI. ro l! co nt a li ze en tr no tc do Remove ==> Cancels the flight Remove ==> Cancels the reservation Remove ==> Emails your coworkers Tuesday, October 12, 2010
  • 61. integration over the web INTEGRATION is DECENTRALIZING the CONTROL delegating to multiple agents distributed systems Tuesday, October 12, 2010
  • 62. does our ‘rest’ sites in 2010 work this way? Tuesday, October 12, 2010
  • 63. so what? that was just keeping an URI. Remove ==> Cancels the flight Remove ==> Cancels the reservation Remove ==> Emails your coworkers Tuesday, October 12, 2010
  • 64. so what? that was just keeping an URI. a t? fo rm hi ch bu tw Remove ==> Cancels the flight Remove ==> Cancels the reservation Remove ==> Emails your coworkers Tuesday, October 12, 2010
  • 65. mas qual o formato do pagamento ou calendário? Tuesday, October 12, 2010
  • 66. #json, #xml, #soap #etc? Tuesday, October 12, 2010
  • 67. qual #json, #xml #etc? Tuesday, October 12, 2010
  • 69. who is that guy? Tuesday, October 12, 2010
  • 70. quem é essa? Tuesday, October 12, 2010
  • 71. fácil? e ela? Tuesday, October 12, 2010
  • 72. fácil? e ela? lh a! fi in ha é m n ão Tuesday, October 12, 2010
  • 73. conteúdo sem semântica não tem valor! Tuesday, October 12, 2010
  • 75. so what? micro formats, media types, rdf etc Tuesday, October 12, 2010
  • 76. so what? nk s! er li hyp w ith ats fo rm ic ro m micro formats, media types, rdf etc Tuesday, October 12, 2010
  • 77. integration over the web Tuesday, October 12, 2010
  • 78. #json, @sergio_caelum Tuesday, October 12, 2010
  • 80. de onde veio o # e o @? Tuesday, October 12, 2010
  • 81. “watching @guilhermecaelum #qconsp *10 great talk” Atenção: esse tweet é só uma sugestão! Tuesday, October 12, 2010
  • 82. controlled vocabulary Tuesday, October 12, 2010
  • 83. emergiu no twitter, por exemplo Tuesday, October 12, 2010
  • 84. inventar antes o controlled vocabulary? Tuesday, October 12, 2010
  • 85. top down? Big Design Up Front O monstro do lago SOAP, longa de 2001 Tuesday, October 12, 2010
  • 86. economizando # busca um voo def voos_de(site)   base = Restfulie.at(site).get   voos = base.link("opensearch").get.fill("flight").with(:from => "GRU", :to => "JFK").get end 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
  • 87. 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
  • 90. email guilherme super viagem Tuesday, October 12, 2010
  • 91. email guilherme super viagem Tuesday, October 12, 2010
  • 92. email guilherme super viagem caelum Tuesday, October 12, 2010
  • 93. email guilherme super viagem caelum Tuesday, October 12, 2010
  • 94. email guilherme super viagem caelum kayak Tuesday, October 12, 2010
  • 95. email guilherme super viagem caelum kayak Tuesday, October 12, 2010
  • 96. email guilherme super viagem caelum kayak Tuesday, October 12, 2010
  • 97. Put your server to REST leonard richardsons model Tuesday, October 12, 2010
  • 98. Server Maturity 1 uri, 1 http verb /services.do?action=install&... Tuesday, October 12, 2010
  • 99. Server Maturity 1 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
  • 100. Server Maturity 1 uri, 1 http verb public class InstallService {   public Response execute() {     return Response.ok()              .type("application/xml")              .entity("<service>...</service>")              .build();   } } Tuesday, October 12, 2010
  • 102. 1 uri, 1 http verb /services.do?action=install&... I know them all beforehand. Tuesday, October 12, 2010
  • 103. 1 uri, 1 http verb /services.do?action=install&... Any change will break all our clients! Tuesday, October 12, 2010
  • 104. a priori knowledge Tuesday, October 12, 2010
  • 105. a priori knowledge = Tuesday, October 12, 2010
  • 106. a priori knowledge = coupling++ Tuesday, October 12, 2010
  • 107. Server Maturity Multiple uris, 1 http verb /install?... Tuesday, October 12, 2010
  • 108. Server Maturity Multiple 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
  • 110. GET hell GET should not imply in undesireable effects Tuesday, October 12, 2010
  • 111. POST hell GET could help us with cache! Tuesday, October 12, 2010
  • 112. Server Maturity Multiple uris, multiple verbs POST /cloud GET /cloud/1547437/software POST /cloud/1547437/software Tuesday, October 12, 2010
  • 113. rails + restfulie rubyonrails.org Tuesday, October 12, 2010
  • 114. rails + restfulie rubyonrails.org class 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   end end Tuesday, October 12, 2010
  • 115. Vraptor vraptor.org/en Tuesday, October 12, 2010
  • 116. Vraptor vraptor.org/en @Resource public class SoftwareResource {   public void install() {     Software software = SoftwareRepository.register (software);     response.created(software);   }   public void uninstall() {     response.deleted(software);   } } Tuesday, October 12, 2010
  • 117. 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
  • 118. 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
  • 119. Uniform Interface++ Resources++ Tuesday, October 12, 2010
  • 120. Http verbs example POST creates PUT replaces PATCH updates DELETE removes GET retrieves OPTIONS tells me what i can do ... Tuesday, October 12, 2010
  • 121. Is a Restful service a cute CRUD? Tuesday, October 12, 2010
  • 123. but there is more! Tuesday, October 12, 2010
  • 124. hypermedia enter amazon.com Tuesday, October 12, 2010
  • 125. hypermedia enter amazon.com search (GET) Tuesday, October 12, 2010
  • 126. hypermedia enter amazon.com search (GET) create a payment (POST) Tuesday, October 12, 2010
  • 127. hypermedia enter amazon.com search (GET) search (GET) create a payment (POST) Tuesday, October 12, 2010
  • 128. hypermedia enter amazon.com search (GET) search (GET) create a basket (POST) create a payment (POST) Tuesday, October 12, 2010
  • 129. hypermedia enter amazon.com follow links search (GET) search (GET) create a basket (POST) create a payment (POST) Tuesday, October 12, 2010
  • 130. hypermedia enter amazon.com follow links search (GET) search (GET) fill forms create a basket (POST) create a payment (POST) Tuesday, October 12, 2010
  • 131. Cloud API GET /user/15 retrieves an user Tuesday, October 12, 2010
  • 132. Cloud API GET /user/15 retrieves an user follow GET machines accesses its machines Tuesday, October 12, 2010
  • 133. 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
  • 134. 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
  • 135. retrieves an user $ curl http://localhost:9998/user/574 -i HTTP/1.1 200 OK ... Tuesday, October 12, 2010
  • 136. user <?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> Tuesday, October 12, 2010
  • 137. user <?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> Tuesday, October 12, 2010
  • 138. maschine maschine maschine $ curl http://localhost:9998/user/574/machines -i HTTP/1.1 200 OK Content-Type: application/xml Tuesday, October 12, 2010
  • 139. 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
  • 140. 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
  • 141. payment <?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> Tuesday, October 12, 2010
  • 142. payment <?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> Tuesday, October 12, 2010
  • 144. @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);   } } Machine.java Tuesday, October 12, 2010
  • 145. @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);   } } Machine.java Tuesday, October 12, 2010
  • 146. @Path("/machines") public class MachineResource { 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; Tuesday, October 12, 2010
  • 147. @Path("/machines") public class MachineResource { 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; Tuesday, October 12, 2010
  • 148. Server Model according to Leonard Richardson, 2008 one uri + one verb Tuesday, October 12, 2010
  • 149. Server Model according to Leonard Richardson, 2008 Ugly one uri + one verb Tuesday, October 12, 2010
  • 150. Server Model according to Leonard Richardson, 2008 multiple uris one uri + one verb Tuesday, October 12, 2010
  • 151. Server Model according to Leonard Richardson, 2008 Less ugly multiple uris one uri + one verb Tuesday, October 12, 2010
  • 152. Server Model according to Leonard Richardson, 2008 multiple verbs multiple uris one uri + one verb Tuesday, October 12, 2010
  • 153. Server Model according to Leonard Richardson, 2008 cute CRUD multiple verbs multiple uris one uri + one verb Tuesday, October 12, 2010
  • 154. Server Model rest according to Leonard Richardson, 2008 hypermedia multiple verbs multiple uris one uri + one verb Tuesday, October 12, 2010
  • 155. JAX-RS wishlist VRaptor and Restfulie Tuesday, October 12, 2010
  • 156. examples vraptor.org/en Tuesday, October 12, 2010
  • 157. 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
  • 158. Convention over Configuration @Resource public 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
  • 159. do you want to avoid copy+paste? Tuesday, October 12, 2010
  • 162. 2. TDD: hard to test @Path("/products") public class Products { coupled to the   @GET implementation   public Response create(     @QueryParam("what") String what) {     // persists     return Response.ok()              .type("application/xml")              .entity("<product>...</product>")              .build();   } } Tuesday, October 12, 2010
  • 163. TDD: mock it coupled to the interface couple-- @Resource public class Services { private final Response response; public Services(Response response) { this.response = response; } public void services(String action) { response.getServiceFor(action).execute(); } } Tuesday, October 12, 2010
  • 164. TDD: mock it coupled to the interface couple-- @Resource public class Services { private final Response response; public Services(Response response) { this.response = response; } public void services(String action) { response.getServiceFor(action).execute(); } } Tuesday, October 12, 2010
  • 165. 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
  • 166. Let us do it for you. @Resource public class SoftwareResource { @Post @Consumes   public void install(Software software) {     software = SoftwareRepository.register(software);     response.created(software);   } } Tuesday, October 12, 2010
  • 167. Let us do it for you. @Resource public class SoftwareResource { @Post @Consumes   public void install(Software software) {     software = SoftwareRepository.register(software);     response.created(software);   } } Tuesday, October 12, 2010
  • 168. 4. URI coupling writing the URI once ...   @GET @Path("/softwares/{id}")   public Response install(@QueryParam("id") Software software) { // ...   } Tuesday, October 12, 2010
  • 169. 4. URI coupling writing the URI again several times @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
  • 170. 4. URI coupling code @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
  • 171. ZERO uri replication @Resource public class SoftwareResource { @Post @Consumes   public void install(Software software) {     // ...     response.use(SoftwareResource.class).show(software);   } } Tuesday, October 12, 2010
  • 172. ZERO uri replication @Resource public class SoftwareResource { @Post @Consumes   public void install(Software software) {     // ...     response.use(SoftwareResource.class).show(software);   } } Tuesday, October 12, 2010
  • 173. 5. Parameter list @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); } // ... } } Tuesday, October 12, 2010
  • 174. Yes, we can do it. @Resource public class MachineResource { @Post ("{m.id}/softwares") public SoftwareResource softwares(Machine m) { Machine machine = new MachineRepository().retrieve(m // ... } } parameter converter chain of responsability Tuesday, October 12, 2010
  • 175. Yes, we can do it. @Resource public class MachineResource { @Post ("{m.id}/softwares") public SoftwareResource softwares(Machine m) { Machine machine = new MachineRepository().retrieve(m // ... } } parameter converter chain of responsability Tuesday, October 12, 2010
  • 176. example restfulie.caelumobjects.com Tuesday, October 12, 2010
  • 177. Response response = client.at ("http://localhost:9998/user/574").get(); 6. Client internal DSLs Tuesday, October 12, 2010
  • 178. 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
  • 179. 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
  • 180. Link link = resource(user).getLink("machine"); response = link.follow().post(new Machine()); double amount = resource(user).refresh(). getAmountDue(); Tuesday, October 12, 2010
  • 181. 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
  • 182. link = resource(user).getLink("payment"); Payment payment = new Payment(amount); response = link.follow().post(payment); System.out.println("payment completed"); Tuesday, October 12, 2010
  • 183. link = resource(user).getLink("payment"); Payment payment = new Payment(amount); response = link.follow().post(payment); System.out.println("payment completed"); i was looking for a DSL and i did not know it! Tuesday, October 12, 2010
  • 184. bottom up design by committe mime type? microformato controlled vocabulary Tuesday, October 12, 2010
  • 185. hypermídia viabilizando a integração através da web Tuesday, October 12, 2010
  • 187. code samples Lucas Cavalcanti (java server) @lucascs Anderson Leite (ruby) @anderson_leite Tuesday, October 12, 2010
  • 189. Further reading Roy Fielding dissertation Tuesday, October 12, 2010
  • 190. Further reading Roy Fielding dissertation Rest in Practice, Jim Webber and others Tuesday, October 12, 2010
  • 191. Further reading Roy Fielding dissertation Rest in Practice, Jim Webber and others Restful Webservices Cookbook, Subbu Allamaraju Tuesday, October 12, 2010
  • 192. Further reading Roy Fielding dissertation Rest in Practice, Jim Webber and others Restful Webservices Cookbook, Subbu Allamaraju Restful Web Services, Richardson and Ruby Tuesday, October 12, 2010
  • 193. Further reading Roy Fielding dissertation Rest in Practice, Jim Webber and others Restful Webservices Cookbook, Subbu Allamaraju Restful Web Services, Richardson and Ruby JAX-RS specification Tuesday, October 12, 2010
  • 194. Further reading 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 Tuesday, October 12, 2010
  • 195. Further reading 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 Tuesday, October 12, 2010
  • 196. Interviews and Presentations Tuesday, October 12, 2010
  • 197. Interviews and Presentations Stefan Tilkov interview on InfoQ Tuesday, October 12, 2010
  • 198. Interviews and Presentations Stefan Tilkov interview on InfoQ http://bit.ly/9RUXKL Tuesday, October 12, 2010
  • 199. Interviews and Presentations Stefan Tilkov interview on InfoQ http://bit.ly/9RUXKL Leonard Richardson’s presentation at QCon Tuesday, October 12, 2010
  • 200. Interviews and Presentations Stefan Tilkov interview on InfoQ http://bit.ly/9RUXKL Leonard Richardson’s presentation at QCon http://bit.ly/dj2W66 Tuesday, October 12, 2010
  • 201. Interviews and Presentations Stefan Tilkov interview on InfoQ http://bit.ly/9RUXKL Leonard Richardson’s presentation at QCon http://bit.ly/dj2W66 Martin Fowler on REST Tuesday, October 12, 2010
  • 202. Interviews and Presentations 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 Tuesday, October 12, 2010
  • 203. Interviews and Presentations Tuesday, October 12, 2010
  • 204. Interviews and Presentations Ian Robinson and Jim Webber interview Tuesday, October 12, 2010
  • 205. Interviews and Presentations Ian Robinson and Jim Webber interview http://bit.ly/aEuzj3 Tuesday, October 12, 2010
  • 206. Interviews and Presentations Ian Robinson and Jim Webber interview http://bit.ly/aEuzj3 Jan Algermissen classification Tuesday, October 12, 2010
  • 207. Interviews and Presentations Ian Robinson and Jim Webber interview http://bit.ly/aEuzj3 Jan Algermissen classification http://bit.ly/cycFBF Tuesday, October 12, 2010
  • 208. Interviews and Presentations Ian Robinson and Jim Webber interview http://bit.ly/aEuzj3 Jan Algermissen classification http://bit.ly/cycFBF Guilherme Silveira on REST clients Tuesday, October 12, 2010
  • 209. Interviews and Presentations 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 Tuesday, October 12, 2010
  • 211. code samples JAX-RS Tuesday, October 12, 2010
  • 212. code samples JAX-RS http://jcp.org/en/jsr/detail?id=311 Tuesday, October 12, 2010
  • 213. code samples JAX-RS http://jcp.org/en/jsr/detail?id=311 Rails Tuesday, October 12, 2010
  • 214. code samples JAX-RS http://jcp.org/en/jsr/detail?id=311 Rails http://rubyonrails.org Tuesday, October 12, 2010
  • 215. code samples JAX-RS http://jcp.org/en/jsr/detail?id=311 Rails http://rubyonrails.org Restfulie Tuesday, October 12, 2010
  • 216. code samples JAX-RS http://jcp.org/en/jsr/detail?id=311 Rails http://rubyonrails.org Restfulie http://restfulie.caelumobjects.com Tuesday, October 12, 2010
  • 217. code samples JAX-RS http://jcp.org/en/jsr/detail?id=311 Rails http://rubyonrails.org Restfulie http://restfulie.caelumobjects.com VRaptor Tuesday, October 12, 2010
  • 218. code samples JAX-RS http://jcp.org/en/jsr/detail?id=311 Rails http://rubyonrails.org Restfulie http://restfulie.caelumobjects.com VRaptor http://vraptor.org/en Tuesday, October 12, 2010