Newsletter |
RESTful Web Services (JAX-RS) Annotations
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 .:: | ||
Thanks nice work…:)
Why @Produce Annotation only for “Get” Requests…..
Nice Work… Clear Explanation for RESTful Web Services…
We can use the @Produces for POST & PUT also…
@Produces will generate specific data like JSON,XML.
Nice explanation for beginners of REST.
Thanks …Good Work
Nice explanations
How about the @CookieParam