Introduction to JAX RS API’s – RESTful Web Services Tutorial

7 years ago Lalit Bhagtani 0

JAX RS stands for Java API for RESTful Web Services. It is a specification for creating RESTful Web Services in Java. These specification are defined via Java Specification Request (JSR) 311. It uses annotations to define the RESTful Web Services. Since it is a specification only, we need to use it’s implementation libraries like Jersey or RESTEasy to create RESTful Web Services.

JAX RS

The most important annotations in JAX RS are listed in the following table.

JAX RS Annotations :-

The most commonly used annotations in JAX RS are listed below :-

  1. @Path(‘Path’) :- Its a class & method level annotation, it is a part of the URI that is used to identify the resource class or method.
  2. @GET :- Its a method level annotation, this annotation indicates that the following method will respond to the HTTP GET request only. It is used to fetch a resource.
  3. @POST :- Its a method level annotation, this annotation indicates that the following method will respond to the HTTP POST request only. It is used to create or update a resource.
  4. @PUT :- Its a method level annotation, this annotation indicates that the following method will respond to the HTTP PUT request only. It is used to create or update a resource.
  5. @DELETE :- Its a method level annotation, this annotation indicates that the following method will respond to the HTTP DELETE request only. It is used to delete a resource.
  6. @HEAD :- Its a method level annotation, this annotation indicates that the following method will respond to the HTTP HEAD request only. It is used to get status of method availability.
  7. @OPTIONS :- Its a method level annotation, this annotation indicates that the following method will respond to the HTTP OPTIONS request only.
  8. @Produces(MediaType.TEXT_PLAIN[, more-types]) :- Its a method or field level annotation, this annotation defines the MIME type that the web service ( method ) can produce as a HTTP response. In simple terms, it states the output format that the method can send to the client.
  9. @Consumes(type[, more-types]) :- Its a method or field level annotation, this annotation defines the MIME type that the web service ( method ) can consumed. In simple terms, it states the input format that the method can accept from the client.
  10. @PathParam() :- It binds the parameter in the path to the parameter passed in the method.
  11. @QueryParam() :- It binds the query parameter in the path to the parameter passed in the method.
  12. @MatrixParam() :- It binds the HTTP matrix parameter to the parameter passed in the method.
  13. @FormParam() :- It binds the form value to the parameter passed in the method.
  14. @HeaderParam() :- It binds the HTTP request header to the parameter passed in the method.
  15. @CookieParam() :- It binds the Cookie to the parameter passed in the method.
  16. @DefaultValue() :-  It assigns a default value to a parameter passed in the method.
  17. @Context :- It is the context of the resource.

References :-

  1. JAX-RS Java Docs

That’s all for Introduction to JAX RS API’s. If you liked it, please share your thoughts in comments section and share it with others too.