REST Service with MultivaluedMap using Jersey

Here I am going to give an example on how MultivaluedMap in REST webservice works.


The most important concept in REST is resources, which are identified by global IDs — typically using URIs. Client applications use HTTP methods (GET/ POST/ PUT/ DELETE) to manipulate the resource or collection of resources. A RESTful Web service is implemented using HTTP and the principles of REST. Typically, a RESTful Web service should define the following aspects:

The base/root URI for the Web service such as http://<host>/<appcontext/contextpath>/<url pattern>/<resources>.
The MIME type of the response data supported, which are JSON/XML/TEXT/HTML etc.
The set of operations supported by the service. (for example, POST, GET, PUT or DELETE).


HTTP methods are mapped to CRUD (create, read, update and delete) actions for a resource. Although you can make slight modifications such as making the PUT method to create or update, the basic patterns are listed as follows.

HTTP GET: Get/List/Retrieve an individual resource or a collection of resources.
HTTP POST: Create a new resource or resources.
HTTP PUT: Update an existing resource or collection of resources.
HTTP DELETE: Delete a resource or collection of resources.


Eclipse, JDK 1.6


A map of key-values pairs. Each key can have zero or more values, where
K – the type of keys maintained by this map
V – the type of mapped values

Now I will go to the coding part and below steps to be followed to create an asynchronous REST servive. We will use grizlly web server for running the service.

Step 1. Create maven project in Eclipse with the below information

Group Id: in.webtuts
Artifact Id: rest

Step 2. Modify the pom.xml file to use jar libraries

 Step 3. Modify web.xml file to use the jersey servlet

Step 4. Create a REST resource class as shown below

Step 5. Create JUnit test class for testing the service

Step 6. Run the JUnit test class.

Console output

That’s all. Thanks for your reading.

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.