20
RESTFul Services Using JAX-RS, JAX-B and Hateoas Shawn Smith director of Software Engineering AIS/ITS/PSU

RESTFul Services

  • 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

Page 1: RESTFul  Services

RESTFul Services

Using JAX-RS, JAX-B and HateoasShawn Smith

director of Software EngineeringAIS/ITS/PSU

Page 2: RESTFul  Services

How My Daughter Sees Me

NERD!!!

Page 3: RESTFul  Services

The deep dark past

Page 4: RESTFul  Services

Not so long ago

struct package{ int messageId; /* Format ddmmyy */ char someDate[7]; char someData[64]; char future[64]; char future[64];};

Page 5: RESTFul  Services

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

Page 6: RESTFul  Services

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>

Page 7: RESTFul  Services

Soap Based Web Services

• Not standardized• Bloated • Uses HTTP simply for tunneling

Page 8: RESTFul  Services

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. …)

Page 9: RESTFul  Services

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.

Page 10: RESTFul  Services

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

Page 11: RESTFul  Services

• 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

Page 12: RESTFul  Services

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

Page 13: RESTFul  Services

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

Page 14: RESTFul  Services

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

Page 15: RESTFul  Services

HTTP Verbs - DELETE

• Purpose – To modify a resource on a server• Return Codes – – 204 (No Content)– 404 (Not Found)

• Idempotent – Yes Safe - No

Page 16: RESTFul  Services

• @GET• @POST• @DELETE• @PUT• @Produces• @Consumes• @Path• @ApplicationPath• @PathParam• @QueryParam• @FormParam

JAX-RS (JSR 311/339)

Page 17: RESTFul  Services

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

Page 18: RESTFul  Services

• @XmlRootElement• @XmlAccessorType• @XmlElement• @XmlTransient• @XmlType• @XmlElementWrapper

JAXB (JSR 222)

Page 19: RESTFul  Services

HATEOAS

• (H) Hypermedia• (A) As • (T) The• (E) Engine• (O) Of • (A) Application• (S) State

Page 20: RESTFul  Services

• 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