0% found this document useful (0 votes)
134 views2 pages

JAX-RS Annotations Guide

This document summarizes common JAX-RS annotations used in RESTful web services including @Path, @GET, @POST, @PUT, @DELETE, @Produces, and @Consumes. It describes what each annotation is used for, whether it applies at the class or method level, and how it controls the request-response behavior of RESTful resources and methods. The annotations map HTTP methods like GET and POST to specific Java methods, define path parameters and query parameters, and specify the media types for requests and responses.

Uploaded by

scorpio
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
134 views2 pages

JAX-RS Annotations Guide

This document summarizes common JAX-RS annotations used in RESTful web services including @Path, @GET, @POST, @PUT, @DELETE, @Produces, and @Consumes. It describes what each annotation is used for, whether it applies at the class or method level, and how it controls the request-response behavior of RESTful resources and methods. The annotations map HTTP methods like GET and POST to specific Java methods, define path parameters and query parameters, and specify the media types for requests and responses.

Uploaded by

scorpio
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 2

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.

----------------------------------------------------------------------------------------------------------------

Table 1. JAX-RS annotations

Annotation Description
Sets the path to base URL + /your_path. The base URL is based on
@PATH(your_path) your application name, the servlet and the URL pattern from the
web.xml configuration file.
Indicates that the following method will answer to an HTTP POST
@POST
request.
Indicates that the following method will answer to an HTTP GET
@GET
request.
Indicates that the following method will answer to an HTTP PUT
@PUT
request.
Indicates that the following method will answer to an HTTP
@DELETE
DELETE request.
@Produces defines which MIME type is delivered by a method
@Produces(MediaType.TEX annotated with @GET. In the example text ("text/plain") is
T_PLAIN[, more-types]) produced. Other examples would be "application/xml" or
"application/json".
@Consumes(type[, more-
@Consumes defines which MIME type is consumed by this method.
types])
Used to inject values from the URL into a method parameter. This
@PathParam way you inject, for example, the ID of a resource into the method to
get the correct object.

You might also like