JAX-RS Tutorial

Java API for RESTful Web Services (JAX-RS), is a set if APIs to developer REST service. JAX-RS is part of the Java EE6, and make developers to develop REST web application easily.
In this series of JAX-RS tutorials, we use both Jersey and RESTEasy, popular JAX-RS implementation.
Happy learning JAX-RS :)
Quick Start
Some quick start examples to use JAX-RS.
- Jersey hello world example
Jersey framework to create a simple REST style web application. - RESTEasy hello world example
RESTEasy framework to create a simple REST style web application.
Basic Examples
Basic annotations and functions to develop REST service.
- JAX-RS @Path URI matching example
JAX-RS URI matching examples. - JAX-RS @PathParam example
Simple way to inject URI parameter that defined in @Path into Java method. - JAX-RS @QueryParam example
Example to get query paremeter in URI path, and also how to define an optional paramater. - JAX-RS @MatrixParam example
Example to get matrix parameters in URI path. - JAX-RS @FormParam example
Example to get HTML post form parameter values. - Get HTTP headers in JAX-RS
Show the use of @HeaderParam and @Context to get HTTP headers. - Download text file from JAX-RS
Example to output a text file for user to download. - Download image file from JAX-RS
Example to output an image file for user to download. - Download pdf file from JAX-RS
Example to output pdf file for user to download. - Download excel file from JAX-RS
Example to output excel file for user to download.
File Upload Examples
How to handle multipart data in JAX-RS.
- File upload example in Jersey
File upload is easy in Jersey. - File upload example in RESTEasy
Two ways to handle file upload in RESTEasy.
Working with XML
XML support in JAX-RS.
- XML example with Jersey + JAXB
Jersey + JAXB to map object to and from XML. - XML example with RESTEasy + JAXB
RESTEasy + JAXB to map object to and from XML.
Working with JSON
JSON support in JAX-RS.
- JSON example with Jersey + Jackson
Jersey + Jackson to map object to and from JSON. - JSON example with RESTEasy + Jackson
RESTEasy + Jackson to map object to and from JSON. - JSON example with RESTEasy + JAXB + Jettison
RESTEasy + JAXB + Jettison to map object to and from JSON.
RESTful Java clients
Create a RESTful Java client to perform “GET” and “POST” request to manipulate json data.
- RESTful Java client with java.net.URL
- RESTful Java client with Apache HttpClient
- RESTful Java client with RESTEasy client
- RESTful Java client with Jersey client
JAX-RS + Spring
Integrate JAX-RS with Spring framework.
- Jersey + Spring integration example
Integrate Jersey with Spring framework. - RESTEasy + Spring integration example
Integrate RESTEasy with Spring framework.
Common Error Messages
Some common error messages in JAX-RS development.
- RESTEasy Unable to scan WEB-INF for JAX-RS annotations, Unexpected end of ZLIB input stream
- ClassNotFoundException : org.jboss.resteasy.plugins.providers.multipart.MultipartInput
- RESTEasy – Could not find message body reader for type: multipart/form-data
- RESTEasy – Could not find MessageBodyWriter for response object of type:xx of media type: application/xml
- Illegal to inject a message body into a singleton into public org.codehaus.jackson.jaxrs.JacksonJsonProvider
- Jersey : The ResourceConfig instance does not contain any root resource classes
- ClassNotFoundException : com.sun.jersey.spi.container.servlet.ServletContainer
References
- Jersey official website
- Jersey user guide
- RESTEasy official website
- RESTEasy user guide
- REST explanation in Wiki

An invaluable resource, very easy to understand.My first step into jax-rs has been really because of this tutorials
Can you please provide an example where a xml payload is sent through REST POST method preferably using spring resttemplate
Hi Thanks for the above example , Could you please share the code for Displaying the JSON into JSP Page
Please explain about the flow of execution jax-rs jersey application
good that works
Thanks a lot for the tutorials. JAX-WS one was really helpful for me. Can you please publish something for Spring Web-Services?
Thanks.
-nilman
Can you post how to do integration testing of Restful services without hard-coding the base URL (can be different for each environment)
DEV:8080/REST/TEST
UAT:8080/REST/TEST
Simple and really useful
Need Help with @PUT and @DELETE type request and client for them..
Yong those are great tutorials… Thank You!!! Could you post a tutorial about using OAuth for authenticating RestFul Web Services ?? It would be highly appreciated.
Keep the good work!!!
Eduardo was right, could you post a tutorial about authenticating client in RestFul Web Services ?? Thank you
I am also waiting for a web site or good code from yong about securing Restful web services… Please post me if you got any worthy resource..!
Yeah, it’s would be very interesting for me too.
Hi Yong,
I am first timer for Web Services. Trying to implement RESTful web service using JAX-RS Jersey APIs. I need to design stateless as well as stateful APIs. I guess I have very good idea on designing stateless APIs but to implement stateful APIs I need to manage session and client state on server. I know REST does not recommend this but this is the application requirement. Any suggestions how to implement stateful APIs? Thanks in advance.
–Milind
is there a tutorial about security in rest? I mean is like implementation of authentication to access resources.
Thank you.,
Have you tutorial or example about restful in struts2?
Could you share it?
Struts2 + restful… a nice combination, may be in future :)
Yong, could you please tell me, how can we handle/get form parameters in REST service when they are in quantity approx. 15 params?
I am aware about @FormParam annotation, but if we cover all the 15 parameters, the method signature become quit long or we can say not readable.
Is there any way ? so that we can directly populate the object based on said 15 form parameters.
I heard about an annotation @Form objRef, but it is no longer exists.
please provide your thoughts on this
thanks,
-Roop
Thank you…!