Upload
fleur
View
82
Download
0
Embed Size (px)
DESCRIPTION
RESTFul Services. Using JAX-RS, JAX-B and Hateoas Shawn Smith d irector of S oftware Engineering AIS/ITS/PSU. How My Daughter Sees Me. NERD!!!. The deep dark past. Not so long ago. struct package { int messageId ; /* Format ddmmyy */ char someDate [7]; - PowerPoint PPT Presentation
Citation preview
RESTFul Services
Using JAX-RS, JAX-B and HateoasShawn Smith
director of Software EngineeringAIS/ITS/PSU
How My Daughter Sees Me
NERD!!!
The deep dark past
Not so long ago
struct package{ int messageId; /* Format ddmmyy */ char someDate[7]; char someData[64]; char future[64]; char future[64];};
Not so long agomodule people { interface address { readonly attribute string streetAddress; readonly attribute string city;}
interface person { readonly attribute string lastName; readonly attribute string firstName; readonly attribute string address;
void setName(in string firstName, in string lastName); void setAddress(in address inAddress); }; };
Not So Long Ago<methodCall> <methodName>someMethod</methodName> <params> <param><value><int>7</int></value></param> <param><value><string>seven</int></value></param> </params></methodCall>
Soap Based Web Services
• Not standardized• Bloated • Uses HTTP simply for tunneling
A RESTFul Approach
• Based on Roy Fielding’s doctoral dissertation
• Injects consistency based on reusing HTTP’s existing verbs
• Allows for context negotiation which can impact payload sizing/versioning (json vs. xml vs. user specific vs. …)
The four possible levels of ‘REST support’ (2)
• “The Swamp of POX.” You’re using HTTP to make RPC calls. HTTP is only really used as a tunnel.
• Resources. Rather than making every call to a service endpoint, you have multiple endpoints that are used to represent resources, and you’re talking to them. This is the very beginnings of supporting REST.
• HTTP Verbs. This is the level that something like Rails gives you out of the box: You interact with these Resources using HTTP verbs, rather than always using POST.
• Hypermedia Controls. HATEOAS. You’re 100% REST compliant.
• Java’s portable API’s intended for use in creating REST compliant web services
• Annotation based descriptors used to covert POJO objects into RESTful services
• Align closely with the HTTP verbs
JAX-RS (JSR 311/339)
• OPTIONS• *POST - create a record C• GET - retrieve a record(s) R• PUT – update a record (possible create) U(C)• DELETE – delete a record D• HEAD• PATCH
HTTP Verbs
HTTP Verbs - POST
• Purpose – Create a new resource on the server
• Return Codes – – 200 (OK)– 202 (Accepted)– 400 (Bad Request)– 409 (Conflict)
• Idempotent – No Safe - No
HTTP Verbs - GET
• Purpose – To retrieve a representation of a resource from a server
• Return Codes – – 200 (OK)– 301 (Permanently Moved)– 303 (See Other)– 304 (Not Modified)– 307 (Temporary Redirect)– 404 (Not Found)
• Idempotent – Yes Safe - Yes
HTTP Verbs - PUT
• Purpose – To modify a resource on a server• Return Codes – – 200 (OK)– 202 (Accepted)– 400 (Bad Request)– 404 (Not Found)– 409 (Conflict)
• Idempotent – Yes Safe - No
HTTP Verbs - DELETE
• Purpose – To modify a resource on a server• Return Codes – – 204 (No Content)– 404 (Not Found)
• Idempotent – Yes Safe - No
• @GET• @POST• @DELETE• @PUT• @Produces• @Consumes• @Path• @ApplicationPath• @PathParam• @QueryParam• @FormParam
JAX-RS (JSR 311/339)
• Java’s API’s used to bind XML (and JSON) to POJO’s
• In a RESTful environment JAXB is used primarily to Marshal and Unmarshall data
JAXB (JSR 222)
• @XmlRootElement• @XmlAccessorType• @XmlElement• @XmlTransient• @XmlType• @XmlElementWrapper
JAXB (JSR 222)
HATEOAS
• (H) Hypermedia• (A) As • (T) The• (E) Engine• (O) Of • (A) Application• (S) State
• Evolution images licensed under This file is licensed under the Creative Commons Attribution ShareAlike 3.0 License. Author commons:User:Tkgd2007
• RESTful Web APIs by Leonard Richardson, Mike Amundsen and Sam Ruby (Sep 12, 2013) • RESTful Java with JAX-RS 2.0 by Bill Burke (Nov 15, 2013) • http://timelessrepo.com/haters-gonna-hateoas• http://barelyenough.org/blog/2008/05/versioning-rest-web-services/• http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm• [email protected]:PennState/web-conference.git