Newsletter

RESTful Web Services (JAX-RS) Annotations

Web Services » on Jul 6, 2014 { 8 Comments } By Sivateja

This tutorial explains important annotations of JAX-RS for creating RESTful web services, friends i am giving these annotations just for your understanding purpose. you better know about these annotations before we go forward with the remaining RESTful web services tutorials.

JAX-RS Annotations

  • @Path(‘Path‘)
  • @GET
  • @POST
  • @PUT
  • @DELETE
  • @Produces(MediaType.TEXT_PLAIN [, more-types])
  • @Consumes(type[, more-types])
  • @PathParam()
  • @QueryParam()
  • @MatrixParam()
  • @FormParam()

@Path() Annotation

  • Its a Class & Method level of annotation
  • This will check the path next to the base URL

Syntax :
Base URL :
http://localhost:(port)/<YourApplicationName>/<UrlPattern In Web.xml>/<path>
Here <path> is the part of URI, and this will be identified by @path annotation at class/method level, you will be able to understand in the next RESTful  hello world tutorial.

@GET

Its a method level of annotation, this annotation indicates that the following method should respond to the HTTP GET request only,  i mean if we annotate our method with @GET, the execution flow will enter that following method if we send GET request from the client

@POST

Its a method level of annotation, this annotation indicates that the following method should respond to the HTTP POST request only.

@PUT

Its a method level of annotation, this annotation indicates that the following method should respond to the HTTP PUT request only.

@DELETE

Its a method level of annotation, this annotation indicates that the following method should respond to the HTTP DELETE request only.

@Produces

Its a method or field level annotation, This tells which MIME type is delivered by the method annotated with @GET.  I mean when ever we send a HTTP GET request to our RESTful service, it will invokes particular method and produces the output in different formats.  There you can specifies in what are all formats (MIME) your method can produce the output, by using @produces annotation.
Remember: We will use @Produces annotation for GET requests only.

@Consumes

This is a class and method level annotation, this will define which MIME type is consumed by the particular method. I mean in which format the method can accept the input from the client.

Will discuss later regarding @PathParam, @QueryParam, @MatrixParam, @FormParam annotations 🙂 , i will talk more about these annotations in the next examples.

​​

You Might Also Like

  ::. About the Author .::

Java4s_Author
Sivateja Kandula - Java/J2EE Full Stack Developer
Founder of Java4s - Get It Yourself, A popular Java/J2EE Programming Blog, Love Java and UI frameworks.
You can sign-up for the Email Newsletter for your daily dose of Java tutorials.

Comments

8 Responses to “RESTful Web Services (JAX-RS) Annotations”
  1. surya says:

    Thanks nice work…:)

  2. Vijay says:

    Why @Produce Annotation only for “Get” Requests…..

  3. Raja says:

    Nice Work… Clear Explanation for RESTful Web Services…

  4. Raja says:

    We can use the @Produces for POST & PUT also…

  5. Shubham Rathore says:

    @Produces will generate specific data like JSON,XML.

  6. Jayhind Rajpoot says:

    Nice explanation for beginners of REST.
    Thanks …Good Work

  7. Rajesh says:

    Nice explanations

  8. A Raghu says:

    How about the @CookieParam

Name*
Mail*
Website



By posting your answer, you agree to our comments policy.
Most Recent Posts from Top Categories
Spring Boot Hibernate Spring
Contact | About Us | Privacy Policy | Advertise With Us

© 2010 - 2024 Java4s - Get It Yourself.
The content is copyrighted to Sivateja Kandula and may not be reproduced on other websites.