Introduction
Hey, Ninja🥷 A REST Programming interface (otherwise called Serene Programming Interface) is an application programming connection point (Programming interface or web Programming interface) that adjusts to the limitations of REST structural style and considers cooperation with Relaxing web administrations. REST represents an authentic state move made by PC researcher Roy Handling.
A Relaxing Programming interface is a building style for an application program interface (Programming interface) that utilizes HTTP solicitations to access and use information. That information can be utilized to GET, PUT, POST, and Erase information types, which allude to the perusing, refreshing, making, and erasing of tasks concerning assets.

RESTful - Application
Allow us to begin composing the genuine Peaceful web administrations with Jersey Structure. Before you start writing your most memorable model utilizing the Jersey System, you must ensure that you have arranged your Jersey climate appropriately as made sense in the Relaxing Web Administrations.
Here, we expect you to have some working information on Obscuration IDE.
In this way, let us continue to compose a basic Jersey Application that will uncover a web administration strategy to show the rundown of clients.
Making a Java Undertaking
The initial step is to make a Unique Web Venture utilizing Shroud IDE. Follow the choice Record → New → Task. Lastly, select the Unique Web Venture wizard from the wizard list. Presently name your task as UserManagement involving the wizard window as displayed in the accompanying screen capture −

When your undertaking is made effectively, you will have the accompanying substance in your Task Wayfarer −
Adding the Expected Libraries
As a subsequent step, we add Jersey Structure and its conditions (libraries) in our task. Duplicate all containers from the following catalogs of download shirt zip organizer in WEB-INF/lib registry of the undertaking.
✳️\jaxrs-ri-2.17\jaxrs-ri\api
✳️\jaxrs-ri-2.17\jaxrs-ri\ext
✳️\jaxrs-ri-2.17\jaxrs-ri\lib
Right snap on your venture name UserManagement and follow the choice accessible in the setting menu − Assemble Way → Design Construct Way to show the Java Fabricate Way window.
Let us Add JARs button accessible under the Libraries tab to add the Containers present in WEBINF/lib catalog.
Making the Source Records
Presently let us make the genuine source documents under the UserManagement project. First, we want to make a bundle called com.codingninjas. To do this, right snap on src in the bundle adventurer segment and follow the choice − New → Bundle. 🗃️
Next, we will make UserService.java, User.java,UserDao.java documents under the com.codingninjas bundle.
User.java
package com.codingninjas;
import java.io.Serializable;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "user")
public class User implements Serializable {
private static final long serialVersionUID = 1L;
private int id;
private String name;
private String profession;
public User(){}
public User(int id, String name, String profession){
this.id = id;
this.name = name;
this.profession = profession;
}
public int getId() {
return id;
}
@XmlElement
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
@XmlElement
public void setName(String name) {
this.name = name;
}
public String getProfession() {
return profession;
}
@XmlElement
public void setProfession(String profession) {
this.profession = profession;
}
}
UserDao.java 🧑💻
package com.codingninjas;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.List;
public class UserDao {
public List<User> getAllUsers(){
List<User> userList = null;
try {
File file = new File("Users.dat");
if (!file.exists()) {
User user = new User(1, "Mahesh", "Teacher");
userList = new ArrayList<User>();
userList.add(user);
saveUserList(userList);
}
else{
FileInputStream fis = new FileInputStream(file);
ObjectInputStream ois = new ObjectInputStream(fis);
userList = (List<User>) ois.readObject();
ois.close();
}
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return userList;
}
private void saveUserList(List<User> userList){
try {
File file = new File("Users.dat");
FileOutputStream fos;
fos = new FileOutputStream(file);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(userList);
oos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
UserService.java
package com.codingninjas;
import java.util.List;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path("/UserService")
public class UserService {
UserDao userDao = new UserDao();
@GET
@Path("/users")
@Produces(MediaType.APPLICATION_XML)
public List<User> getUsers(){
return userDao.getAllUsers();
}
}
There are two significant focuses to be noted about the principal program,
UserService.java
🔅The initial step is to indicate a way for the web administration utilizing @Path explanation to the UserService.
🔅The subsequent step is to show a way for the specific web administration technique using @Path answer to strategy for UserService.
Making the Web.xml design Record 💿
You really want to make an Internet xml Setup record which is a XML document and is utilized to indicate the Jersey system servlet for our application.
<?xml version = "1.0" encoding = "UTF-8"?>
<web-app xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xmlns = "http://java.sun.com/xml/ns/javaee"
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">
<display-name>User Management</display-name>
<servlet>
<servlet-name>Jersey RESTful Application</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.codingninjas</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Jersey RESTful Application</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>

Sending the Program
When you are finished making source and web arrangement records, you are prepared for this step, incorporating and running your program. To do this, utilizing Overshadowing, send out your application as a conflicting record and convey a similar in tomcat.
To make a Conflict record utilizing shroud, follow the choice Document → send out → Web → War Document; lastly, select venture UserManagement and objective envelope. To send a conflict document in Tomcat, place the UserManagement.war in the Tomcat Establishment Catalog → webapps registry and begin the Tomcat.



