Loading ...
Sorry, an error occurred while loading the content.
 

JAX-RS 2.0 Support for HalBuilder

Expand Messages
  • Mark Derricutt
    lo all, Just added a super simple JAX-RS 2.0 support module for my HalBuilder JVM API which I intend to release sometime over the weekend:
    Message 1 of 1 , Jun 28, 2013
      'lo all,

      Just added a super simple JAX-RS 2.0 support module for my HalBuilder
      JVM API which I intend to release sometime over the weekend:

      https://github.com/HalBuilder/halbuilder-jaxrs

      along with a small sample application at:


      https://github.com/HalBuilder/halbuilder-examples/tree/develop/halbuilder-jersey-example

      Basically, when configuring Jersey ( I've not looked at RestEasy yet )
      you simple tell it to also scan the
      "com.theoryinpractise.halbuilder.jaxrs" package to pick up the support
      classes, then in your resource class just return your representation object:

      @GET
      @Produces({RepresentationFactory.HAL_JSON,
      RepresentationFactory.HAL_XML})
      public Representation getIt() {
      Representation rep = representationFactory.newRepresentation();
      rep.withProperty("message", "Got it!");
      return rep;
      }

      and voila - content neg. is all handled by JAX-RS out of the box:

      $ curl -H "Accept: application/hal+xml"
      http://localhost:8080/myapp/myresource
      <resource>
      <link rel="website" href="http://gotohal.net" />
      <message>Got it!</message>
      </resource>

      $ curl http://localhost:8080/myapp/myresource
      {
      "_links" : {
      "website" : {
      "href" : "http://gotohal.net"
      }
      },
      "message" : "Got it!"
      }

      So far I've added the @Produces side of things, tho @Consumes should be
      just as simple and should be added before the release.

      Note that the support ONLY works for returning
      Representation/ReadableRepresentation and not arbitrary objects - this
      is me trying to make you think of links/representations etc. as
      first-class things.

      Mark
    Your message has been successfully submitted and would be delivered to recipients shortly.