Your SlideShare is downloading. ×
0
Jax-rs-js Tutorial
Jax-rs-js Tutorial
Jax-rs-js Tutorial
Jax-rs-js Tutorial
Jax-rs-js Tutorial
Jax-rs-js Tutorial
Jax-rs-js Tutorial
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

Jax-rs-js Tutorial

2,368

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.

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,368
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
29
Comments
0
Likes
0
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. JAX-RS-JS Tutorial https://github.com/marcbaechinger/jax-rs-js twitter: @marcbaechinger [email_address]
  • 2. What is jax-rs-js ?
    • JavaScript generator
    • 3. Mirrors JAX-RS annotated REST services
    • 4. JaxRsJsServlet to serve JS files
    • 5. JS minification by default
    • 6. Easy to use API
    • 7. Handles WebApplicationException
    • 8. relies on @MediaType.JSON
  • 9. Which features are supported?
    • @Path on class and method level
    • 10. @GET, @POST, @PUT, @DELETE
    • 11. @MediaType.JSON
    • 12. @PathParam(“foo”) on method arguments
    • 13. List and Arrays as method arguments
    • 14. List and Arrays as return values
  • 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. 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. 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. THX! Follow @marcbaechinger [email_address]

×