Your SlideShare is downloading. ×
0
JAX-RS-JS Tutorial https://github.com/marcbaechinger/jax-rs-js twitter: @marcbaechinger [email_address]
What is jax-rs-js ? <ul><li>JavaScript generator
Mirrors JAX-RS annotated REST services
JaxRsJsServlet  to serve JS files
JS minification by default
Easy to use API
Handles  WebApplicationException
Upcoming SlideShare
Loading in...5
×

Jax-rs-js Tutorial

2,383

Published on

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.

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

  • Be the first to like this

No Downloads
Views
Total Views
2,383
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
29
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Jax-rs-js Tutorial"

  1. 1. JAX-RS-JS Tutorial https://github.com/marcbaechinger/jax-rs-js twitter: @marcbaechinger [email_address]
  2. 2. What is jax-rs-js ? <ul><li>JavaScript generator
  3. 3. Mirrors JAX-RS annotated REST services
  4. 4. JaxRsJsServlet to serve JS files
  5. 5. JS minification by default
  6. 6. Easy to use API
  7. 7. Handles WebApplicationException
  8. 8. relies on @MediaType.JSON </li></ul>
  9. 9. Which features are supported? <ul><li>@Path on class and method level
  10. 10. @GET, @POST, @PUT, @DELETE
  11. 11. @MediaType.JSON
  12. 12. @PathParam(“foo”) on method arguments
  13. 13. List and Arrays as method arguments
  14. 14. List and Arrays as return values </li></ul>
  15. 15. 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; } }
  16. 16. 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>
  17. 17. 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>
  18. 18. THX! Follow @marcbaechinger [email_address]
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×