Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
RESTful WebServices

     Florian Motlik
Webservices now

 RPC Style
 SOAP is complicated
 HTTP not fully used (only post)
 HTTP Tools not usable (proxy, cache, Fi...
RESTful Webservices

   Representational State Transfer
   Introduced by Roy Fielding in Dissertation
      http://www.ics...
Design Principles

  State and Functionality abstracted in resources
     Representations transferred to Client
     Diffe...
Resources

 WebService for determining status
 of Healthy Food in Healthy Food
 machine
 URLS:
     http://example.com/hea...
JAX-RS

 Specified in JSR-311
 Final Release in October 2008
 Uses Annotations heavily
 Different Implementations
     Jer...
Simple Example

@Path(quot;/libraryquot;) - Also regular Expressions possible in @Path
public class Library {
@GET
@Path(q...
Further Annotations

  QueryParam
       GET /books?num=5
       @GET
       public String getBooks(@QueryParam(quot;numqu...
Providers

 Automatic Marshalling and Unmarshalling
 XML, JSON provided
 @Consumes or @Produces with content Type onto Met...
Upcoming SlideShare
Loading in …5
×

JSUG - RESTful Web Services by Florian Motlik

1,238 views

Published on

visit http://jsug.fsinf.at

Published in: Technology
  • Be the first to comment

JSUG - RESTful Web Services by Florian Motlik

  1. 1. RESTful WebServices Florian Motlik
  2. 2. Webservices now RPC Style SOAP is complicated HTTP not fully used (only post) HTTP Tools not usable (proxy, cache, Firewall) Another layer needed for inspection of SOAP Great for Starting Action on Server Not so Great for retrieving State
  3. 3. RESTful Webservices Representational State Transfer Introduced by Roy Fielding in Dissertation http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm One of main Authors of HTTP Specification Web is RESTful Service Roadmap: Design Principles Resources JAX-RS - Java API for Restful WebServices
  4. 4. Design Principles State and Functionality abstracted in resources Representations transferred to Client Different Reps possible (XML, Html, JSON, ...) Addressability for every Resource e.g. every Resource has own URL Uniform Interface Well defined Operations for CRUD Content-Types for Content Negotiation Protocol attributes Client-Server Stateless - No Cookies or other Extensions Cacheable Layered - Caches, Firewalls, Tunnels, ... supported
  5. 5. Resources WebService for determining status of Healthy Food in Healthy Food machine URLS: http://example.com/healthy Gives list of all possible Items http://example.com/healthy/1 Gives info for one product(left, price, ...) Machine is abstracted away as resource Representations can be obtained
  6. 6. JAX-RS Specified in JSR-311 Final Release in October 2008 Uses Annotations heavily Different Implementations Jersey -reference implementation RESTeasy - from JBOSS Working together with SEAM
  7. 7. Simple Example @Path(quot;/libraryquot;) - Also regular Expressions possible in @Path public class Library { @GET @Path(quot;/booksquot;) public String getBooks() {...} @PUT @Path(quot;/book/{isbn}quot;) public void addBook(@PathParam(quot;isbnquot;) String id) {...} @DELETE @Path(quot;/book/{id}quot;) public void removeBook(@PathParam(quot;idquot;) String id {...} }
  8. 8. Further Annotations QueryParam GET /books?num=5 @GET public String getBooks(@QueryParam(quot;numquot;) int num) { } HeaderParam @PUT public void put(@HeaderParam(quot;Content-Typequot;) MediaType contentType) MatrixParam GET http://host.com/library/book;name=SomeBook @GET public String getBook(@MatrixParam(quot;namequot;) String name) {...} CookieParam @GET public String getBooks(@CookieParam(quot;sessionidquot;) int id) {...} DefaultValue @GET public String getBooks(@QueryParam(quot;numquot;) @DefaultValue(quot;10quot;) int num) {...}
  9. 9. Providers Automatic Marshalling and Unmarshalling XML, JSON provided @Consumes or @Produces with content Type onto Method Method returns Object and it is marshalled

×