A Developer Gateway To IT World...

Techie Uncle Software Testing Core Java Java Spring C Programming Operating System HTML 5 Java 8 ES6 Project

A simple approach to Develop RESTful Web Services with JAX-RS

Developing RESTful Web Services with JAX-RS

Restful Web Services Quick Link at Oracle Tutorial is available. However, to simplify JAX-RS, I'm going to provide you important information and an example.
The JAX-RS API uses Java programming language annotations to simplify the development of RESTful web services.

Actually, restful webservices JAXRS is better than JAXWS. In JAXRS you can integrate with another web application which may be created in PHP or .DOT net language's. It means that there is no dependencies on particular language's. In today world of computer science you can mix any language like server or client.

Let's Understand an example that there is a client who wants to execute server path and Server code.

package com.Dream.restClient;

import java.net.URI; 
import javax.ws.rs.client.Client; 
import javax.ws.rs.client.ClientBuilder; 
import javax.ws.rs.client.WebTarget; 
import javax.ws.rs.core.MediaType; 
import javax.ws.rs.core.UriBuilder; 
import org.glassfish.jersey.client.ClientConfig; 

//JAX-RS Client Code
public class ClientTest {

    public static void main(String[] args)
        ClientConfig config = new ClientConfig(); 
        Client client = ClientBuilder.newClient(config); 
        WebTarget target = client.target(getBaseURI()); 
    private static URI getBaseURI()
        return UriBuilder.fromUri("http://localhost:8080/Dream/").build(); 

Output :

Navneet Kaur Daughter's Name is Pia From Bihar

The above client is getting path from this rest Application. 
Root resource classes or request method designator, such as @GET@PUT@POST, or @DELETE.
will be used in the rest apllication classes.

package com.Dream.rest;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

public class UserController {
    public String User()
        //registered User at programmingshifts.com
        Programmingshifts_User  obj = new Programmingshifts_User(101,"Pia","Bihar");
        return "Navneet Kaur Daughter's Name is "+obj.getName()+" From "+obj.getAddress(); 

class Programmingshifts_User
    int id;
    String name, address;
    public Programmingshifts_User(int id, String name, String address) {
        this.id = id;
        this.name = name;
        this.address = address;
    public String toString() {
        return "Programmingshifts_User [id=" + id + ", name=" + name + ", address=" + address + "]";

    public int getId() {
        return id;
    public void setId(int id) {
        this.id = id;
    public String getName() {
        return name;
    public void setName(String name) {
        this.name = name;
    public String getAddress() {
        return address;
    public void setAddress(String address) {
        this.address = address;

This is the web.xml file in dynamic web project which contains servlet class information and mapping.

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">

   <servlet-name>Jersey REST Service</servlet-name>

    <servlet-name>Jersey REST Service</servlet-name>

When User want to get information on url while fetching request, then it will look like as below: