• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Jax-rs-js Tutorial
 

Jax-rs-js Tutorial

on

  • 2,696 views

Introduction into jax-rs-js. jax-rs-js is a tool to access REST services implemented with JAX-RS (Jersey) by a clean interface derived from the Java service and its JAX-RS annotations.

Introduction into jax-rs-js. jax-rs-js is a tool to access REST services implemented with JAX-RS (Jersey) by a clean interface derived from the Java service and its JAX-RS annotations.

Statistics

Views

Total Views
2,696
Views on SlideShare
2,685
Embed Views
11

Actions

Likes
0
Downloads
28
Comments
0

2 Embeds 11

http://paper.li 10
http://twitter.com 1

Accessibility

Upload Details

Uploaded via as OpenOffice

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Jax-rs-js Tutorial Jax-rs-js Tutorial Presentation Transcript

    • JAX-RS-JS Tutorial https://github.com/marcbaechinger/jax-rs-js twitter: @marcbaechinger [email_address]
    • What is jax-rs-js ?
      • JavaScript generator
      • Mirrors JAX-RS annotated REST services
      • JaxRsJsServlet to serve JS files
      • JS minification by default
      • Easy to use API
      • Handles WebApplicationException
      • relies on @MediaType.JSON
    • Which features are supported?
      • @Path on class and method level
      • @GET, @POST, @PUT, @DELETE
      • @MediaType.JSON
      • @PathParam(“foo”) on method arguments
      • List and Arrays as method arguments
      • List and Arrays as return values
    • JAX-RS example @Path(&quot;/note&quot;) public class NotesService { @GET @Produces(MediaType.APPLICATION_JSON) public List<Note> getAll() { // ... return notes; } @POST @Path(&quot;/ {id} /comments/ {commentId} &quot;) @Produces(MediaType.APPLICATION_JSON) public List<Comment> getComments( @PathParam(&quot;id&quot;) String noteId, @PathParam(&quot;commentId&quot;) String commentId) { // ... return rs; } @PUT @Path(&quot;/batchArray/{id}&quot;) @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public List<Note> addNotesAsArray( @PathParam(“id”) Long id, Note[] notes ) { // ... return notes; } }
    • Deliver JavaScript by a Servlet <servlet> <servlet-name>JaxRsJsServlet</servlet-name> <servlet-class> ch.mbae.jaxjs.container.JaxRsJsServlet </servlet-class> <init-param> // MUST MATCH TO JAX-RS servlet path <param-name> jaxrs.servlet.path </param-name> <param-value> /resources </param-value> </init-param> <init-param> <param-name> library.default </param-name> <param-value> ch.mbae.notes.services.NotesService, com.foo.services.BarService </param-value> </init-param> <init-param> <param-name> config.minification </param-name> <param-value> false </param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>JaxRsJsServlet</servlet-name> <url-pattern> /resources-js/* </url-pattern> </servlet-mapping>
    • Request JS file with HTML page <script src=&quot;../js/jquery.js&quot;> </script> <script src=&quot; <%= request.getContextPath() %>/resources-js/default &quot;> </script> <script> $(function() { jaxjs.services.NotesService.getAll (function(notes) { // do something with notes retrieved from service }); }); </script>
    • THX! Follow @marcbaechinger [email_address]