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