Your SlideShare is downloading. ×
0
RESTful Groovy
RESTful Groovy
RESTful Groovy
RESTful Groovy
RESTful Groovy
RESTful Groovy
RESTful Groovy
RESTful Groovy
RESTful Groovy
RESTful Groovy
RESTful Groovy
RESTful Groovy
RESTful Groovy
RESTful Groovy
RESTful Groovy
RESTful Groovy
RESTful Groovy
RESTful Groovy
RESTful Groovy
RESTful Groovy
RESTful Groovy
RESTful Groovy
RESTful Groovy
RESTful Groovy
RESTful Groovy
RESTful Groovy
RESTful Groovy
RESTful Groovy
RESTful Groovy
RESTful Groovy
RESTful Groovy
RESTful Groovy
RESTful Groovy
RESTful Groovy
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

RESTful Groovy

2,546

Published on

Speaker: Kenneth Kousen …

Speaker: Kenneth Kousen
The JAX-RS 2.0 specification is part of Java EE 7, but can be used now. It contains the expected annotations for the HTTP verbs (@GET, @POST, and so on) and mechanisms for retrieving variables, but only a few methods for doing hypermedia. This presentation will review those techniques by adding both structural and transitional links to resource representations. Groovy is used to simplify the code and also to implement a MessageBodyWriter for JSON data.
In addition to simplifying the implementation classes, Groovy also supplies a RESTful client class from the HttpBuilder project. That will be used, as well as the native client implementation classes in JAX-RS 2.0, to build Spock tests for RESTful services.

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,546
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
25
Comments
0
Likes
3
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. RESTful Groovy Implementing JAX-RS with Groovy
  • 2. Contact Info Ken Kousen ken.kousen@kousenit.com @kenkousen Making Java Groovy http://manning.com/kousen
  • 3. REST Term from Ph.D. thesis by Roy Fielding Co-founder Apache HTTP Server project Part of IETF working groups for: URI, HTTP, HTML Architectural Styles and the Design of Network-based Software Architectures
  • 4. REST Representational State Transfer - Addressable resources - Uniform interface - Content negotiation - Stateless services
  • 5. Addressable Resources Use URLs to access items (no verbs in URLs)
  • 6. Uniform Interface HTTP verbs GET POST PUT DELETE ---HEAD OPTIONS PATCH
  • 7. Safe vs Idempotent Safe → no server side changes GET
  • 8. Idempotent Idempotent requests can be repeated No additional effects GET PUT DELETE
  • 9. Http Status Codes 200s → good 200 OK, 201 created, 204 no content 300s → moved 400s → you messed up 404 not found, 409 conflict (see 418, 420 for fun) 500s → we messed up
  • 10. RESTful service Implementations GET → retrieve data POST → insert data set Location header for new item PUT → update data DELETE → remove data
  • 11. RESTful service Yes, that’s a URL-driven database
  • 12. RESTful service Yes, that’s a URL-driven database (Hypermedia advocates are squirming, but we’ll get there)
  • 13. Content Negotiation Client can request representations Usually via MIME type in Accept header
  • 14. Stateless Services No state maintained in service All interactions via self-contained requests
  • 15. HATEOAS Hypermedia As The Engine Of Application State An unpronounceable acronym with the word HATE in it
  • 16. Hypermedia Goal is true decoupling Client asks for first URL Response includes links Works like the web, but programmatically
  • 17. The Java Approach JAX-RS 1.1 Implements JSR 311 spec JAX-RS 2.0 Implements JSR 339 spec
  • 18. JAX-RS Implementations Jersey (R.I.) RestEasy Restlets Restfulie Apache CXF
  • 19. JAX-RS Note: Spring REST annotations do NOT implement JAX-RS
  • 20. POGO Resources are POGOs Representations are based on MIME-types Hypermedia comes from links and annotations
  • 21. Server Side
  • 22. JAX-RS Annotations @GET, @POST, @PUT, @DELETE @Produces, @Consumes @Path, @PathParam @Context
  • 23. JAX-RS Classes, interfaces, enums Response Response.ResponseBuilder UriInfo UriBuilder MediaType
  • 24. Client Side HttpBuilder project wraps Apache HTTP Client http://groovy.codehaus.org/modules/http-builder/ Source code: https://github.com/jgritman/httpbuilder
  • 25. Client Side JAX-RS 2.0 includes client library ClientBuilder WebTarget
  • 26. Hypermedia
  • 27. Hypermedia
  • 28. Trivia Did you know? Neither the word “hypermedia” nor HATEOAS appear anywhere in the JSR 399 specification (No, I don’t know why either)
  • 29. Links Adding transitional links Response.ResponseBuilder link (several overloads) links Link class
  • 30. Links Adding structural links Use Link attributes inside POGO Add JAXB annotations @XmlJavaTypeAdapter(JaxbAdapter)
  • 31. Links Customizing links Groovy API: JsonBuilder JsonSlurper Use a custom JAX-RS provider
  • 32. Custom Provider Implement: MessageBodyReader<T> MessageBodyWriter<T>
  • 33. Summary JAX-RS 2.0 specification Jersey reference implementation Hypermedia done through links Groovy simplifies code No major changes unless custom provider HttpBuilder client

×