1 / 20

RESTFul Services

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

fleur
Download Presentation

RESTFul Services

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. How My Daughter Sees Me NERD!!!

  3. The deep dark past

  4. Not so long ago struct package { intmessageId; /* Format ddmmyy */ char someDate[7]; char someData[64]; char future[64]; char future[64]; };

  5. Not so long ago module 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);   }; };

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

  7. Soap Based Web Services • Not standardized • Bloated • Uses HTTP simply for tunneling

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

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

  10. JAX-RS (JSR 311/339) • 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

  11. HTTP Verbs • 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

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

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

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

  15. HTTP Verbs - DELETE • Purpose – To modify a resource on a server • Return Codes – • 204 (No Content) • 404 (Not Found) • Idempotent – Yes Safe - No

  16. JAX-RS (JSR 311/339) • @GET • @POST • @DELETE • @PUT • @Produces • @Consumes • @Path • @ApplicationPath • @PathParam • @QueryParam • @FormParam

  17. JAXB (JSR 222) • Java’s API’s used to bind XML (and JSON) to POJO’s • In a RESTfulenvironment JAXB is used primarily to Marshal and Unmarshall data

  18. JAXB (JSR 222) • @XmlRootElement • @XmlAccessorType • @XmlElement • @XmlTransient • @XmlType • @XmlElementWrapper

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

  20. Evolution images licensed under This file is licensed under the Creative CommonsAttribution 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 • git@github.com:PennState/web-conference.git

More Related