SlideShare a Scribd company logo
1
Hello World RESTful web service tutorial
Balázs Simon (sbalazs@iit.bme.hu), BME IIT, 2015
1 Introduction
This document describes how to create a Hello World RESTful web service in Eclipse using JAX-RS and
WildFly.
2 RESTful service
Create a new Dynamic Web Project in Eclipse called HelloRest. Make sure to select Generate web.xml
deployment descriptor at the end of the wizard. The web project should look like this:
2
The JAX-RS annotated classes will be handled by a special servlet. This servlet must be declared in the
web.xml file. Change the web.xml file so that it contains the following lines shown with yellow
background:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="3.1"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<display-name>HelloRest</display-name>
<servlet-mapping>
<servlet-name>javax.ws.rs.core.Application</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
Create a new interface called IHello and a class called Hello in the src folder under the package
hellorest:
3
The IHello.java should contain the following code:
package hellorest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.QueryParam;
@Path("hello")
public interface IHello {
@GET
@Path("sayHello")
public String sayHello(@QueryParam("name") String name);
}
The Hello.java should contain the following code:
package hellorest;
public class Hello implements IHello {
@Override
public String sayHello(String name) {
return "Hello: "+name;
}
}
Deploy the application to the server. It should be deployed without errors:
To test the service, type the following URL into a browser (FireFox, Chrome, IE, etc.):
http://localhost:8080/HelloRest/rest/hello/sayHello?name=me
The response should be:
4
The URL has the following structure:
 http://localhost:8080 – the protocol, domain name and port number of the server
 /HelloRest – the name of the web application
 /rest – the mapping of the REST servlet in the web.xml file
 /hello – the @Path mapping of the IHello interface
 /sayHello – the @Path mapping of the sayHello operation
 ?name=me – the name and value passed as a @QueryParam
3 HTML client
Create an HTML file called HelloClient.html under the WebContent folder:
The contents of the file should be the following:
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Hello REST client</title>
</head>
<body>
<form method="get" action="rest/hello/sayHello">
Type your name: <input type="text" name="name"/>
<input type="submit" value="Say hello"/>
</form>
</body>
</html>
5
Redeploy the application to the server, and open the following URL in a browser:
http://localhost:8080/HelloRest/HelloClient.html
This is where the HTML is accessible. The following page should be loaded in the browser:
Type something in the text field and click the Say hello button:
The result should be the following:
4 Java client using RESTeasy
RESTeasy is the JAX-RS implementation of the WildFly server. It also has a client library, which can be
used in console applications. This example will show how.
RESTeasy requires some additional dependencies, so the easiest way to create a client is to use Maven.
Create a new Maven Project in Eclipse called HelloRestClient:
6
Click Next, and select the Create a simple project check-box:
Click Next and type HelloRestClient for both Group Id and Artifact Id:
7
Click Finish, and the project should look like this:
Edit the pom.xml and add the following lines shown with yellow background:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>HelloRestClient</groupId>
<artifactId>HelloRestClient</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<version>3.0.10.Final</version>
</dependency>
</dependencies>
</project>
4.1 Untyped client
Create a new class called UntypedHelloClient under the package hellorestclient with the following
content:
package hellorestclient;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.Response;
public class UntypedHelloClient {
public static void main(String[] args) {
try{
// Create a new RESTeasy client through the JAX-RS API:
Client client = ClientBuilder.newClient();
// The base URL of the service:
WebTarget target = client.target("http://localhost:8080/HelloRest/rest");
8
// Building the relative URL manually for the sayHello method:
WebTarget hello =
target.path("hello").path("sayHello").queryParam("name", "me");
// Get the response from the target URL:
Response response = hello.request().get();
// Read the result as a String:
String result = response.readEntity(String.class);
// Print the result to the standard output:
System.out.println(result);
// Close the connection:
response.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
The project should look like this:
Right click on the UntypedHelloClient.java and select Run As > Java Application. It should print the
following:
9
4.2 Typed client
Create an interface called IHello under the package hellorestclient with the following content:
package hellorestclient;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.QueryParam;
@Path("hello")
public interface IHello {
@GET
@Path("sayHello")
public String sayHello(@QueryParam("name") String name);
}
Create a class called TypedHelloClient under the package hellorestclient with the following content:
package hellorestclient;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.WebTarget;
import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget;
public class TypedHelloClient {
public static void main(String[] args) {
try {
// Create a new RESTeasy client through the JAX-RS API:
Client client = ClientBuilder.newClient();
// The base URL of the service:
WebTarget target = client.target("http://localhost:8080/HelloRest/rest");
// Cast it to ResteasyWebTarget:
ResteasyWebTarget rtarget = (ResteasyWebTarget)target;
// Get a typed interface:
IHello hello = rtarget.proxy(IHello.class);
// Call the service as a normal Java object:
String result = hello.sayHello("me");
// Print the result:
System.out.println(result);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
Right click on the TypedHelloClient.java and select Run As > Java Application. It should print the
following:

More Related Content

What's hot (20)

PPTX
Using schemas in parsing xml part 2
Alex Fernandez
 
PDF
Jsp & Ajax
Ang Chen
 
PPTX
Mule esb first http connector
Germano Barba
 
PPS
JSP Error handling
kamal kotecha
 
PPTX
JSP- JAVA SERVER PAGES
Yoga Raja
 
PPTX
Java Servlet
Yoga Raja
 
PPTX
Asp Net Advance Topics
Ali Taki
 
ZIP
ASP.Net Presentation Part1
Neeraj Mathur
 
PDF
JSP
corneliuskoo
 
PPTX
jsp MySQL database connectivity
baabtra.com - No. 1 supplier of quality freshers
 
PPTX
ASP.NET Lecture 2
Julie Iskander
 
PDF
JAVA EE DEVELOPMENT (JSP and Servlets)
Talha Ocakçı
 
PPTX
Soap Component
sivachandra mandalapu
 
PPT
Asp.net.
Naveen Sihag
 
PPT
Installation of Drupal on Windows XP with XAMPP
Rupesh Kumar
 
PDF
Dicoding Developer Coaching #20: Android | Apa itu Content Provider?
DicodingEvent
 
PPTX
Web Technologies - forms and actions
Aren Zomorodian
 
PPT
ASP.NET 03 - Working With Web Server Controls
Randy Connolly
 
PPTX
java Servlet technology
Tanmoy Barman
 
Using schemas in parsing xml part 2
Alex Fernandez
 
Jsp & Ajax
Ang Chen
 
Mule esb first http connector
Germano Barba
 
JSP Error handling
kamal kotecha
 
JSP- JAVA SERVER PAGES
Yoga Raja
 
Java Servlet
Yoga Raja
 
Asp Net Advance Topics
Ali Taki
 
ASP.Net Presentation Part1
Neeraj Mathur
 
jsp MySQL database connectivity
baabtra.com - No. 1 supplier of quality freshers
 
ASP.NET Lecture 2
Julie Iskander
 
JAVA EE DEVELOPMENT (JSP and Servlets)
Talha Ocakçı
 
Soap Component
sivachandra mandalapu
 
Asp.net.
Naveen Sihag
 
Installation of Drupal on Windows XP with XAMPP
Rupesh Kumar
 
Dicoding Developer Coaching #20: Android | Apa itu Content Provider?
DicodingEvent
 
Web Technologies - forms and actions
Aren Zomorodian
 
ASP.NET 03 - Working With Web Server Controls
Randy Connolly
 
java Servlet technology
Tanmoy Barman
 

Viewers also liked (15)

PDF
uae views on big data
Aravindharamanan S
 
PDF
Tomcat + other things
Aravindharamanan S
 
PDF
Sun==big data analytics for health care
Aravindharamanan S
 
PDF
Big data-analytics-2013-peer-research-report
Aravindharamanan S
 
PDF
Android chapter18 c-internet-web-services
Aravindharamanan S
 
PPT
Personalizing the web building effective recommender systems
Aravindharamanan S
 
PDF
Chapter 2 research methodlogy
Aravindharamanan S
 
PPT
Cs548 s15 showcase_web_mining
Aravindharamanan S
 
PPT
Introduction to recommendation system
Aravindharamanan S
 
PPT
Content based recommendation systems
Aravindharamanan S
 
PDF
Android ui layouts ,cntls,webservices examples codes
Aravindharamanan S
 
PPT
Combining content based and collaborative filtering
Aravindharamanan S
 
DOCX
Database development connection steps
Aravindharamanan S
 
PDF
Full xml
Aravindharamanan S
 
PDF
Sql developer usermanual_en
Aravindharamanan S
 
uae views on big data
Aravindharamanan S
 
Tomcat + other things
Aravindharamanan S
 
Sun==big data analytics for health care
Aravindharamanan S
 
Big data-analytics-2013-peer-research-report
Aravindharamanan S
 
Android chapter18 c-internet-web-services
Aravindharamanan S
 
Personalizing the web building effective recommender systems
Aravindharamanan S
 
Chapter 2 research methodlogy
Aravindharamanan S
 
Cs548 s15 showcase_web_mining
Aravindharamanan S
 
Introduction to recommendation system
Aravindharamanan S
 
Content based recommendation systems
Aravindharamanan S
 
Android ui layouts ,cntls,webservices examples codes
Aravindharamanan S
 
Combining content based and collaborative filtering
Aravindharamanan S
 
Database development connection steps
Aravindharamanan S
 
Sql developer usermanual_en
Aravindharamanan S
 
Ad

Similar to Rest hello world_tutorial (20)

DOCX
Build Your First Java Jersey JAX-RS REST Web Service in less than 15 Minutes
Robert Li
 
PPTX
Building Restful Web Services with Java
Vassil Popovski
 
DOCX
Html servlet example
rvpprash
 
PPT
Developing RESTful WebServices using Jersey
b_kathir
 
PDF
Restful web services_tutorial
philip75020
 
PDF
Introduction to Restful Web Services
weili_at_slideshare
 
PDF
E-Services TP2 ISI by Ettaieb Abdessattar
Abdessattar Ettaieb
 
PPTX
Introduction to RESTful Webservices in JAVA
psrpatnaik
 
PDF
RESTful Java With JAX RS 1st Edition Bill Burke
rohismhmob88
 
PDF
JavaEE and RESTful development - WSO2 Colombo Meetup
Sagara Gunathunga
 
PDF
RESTful Java With JAX RS 1st Edition Bill Burke
jolokmertah
 
PDF
RESTful web service with JBoss Fuse
ejlp12
 
PDF
JavaEE6 my way
Nicola Pedot
 
PPTX
Rest overview briefing
◄ vaquar khan ► ★✔
 
PDF
Jersey
Yung-Lin Ho
 
PPTX
RESTful application with JAX-RS and how to expose and test them
Kumaraswamy M
 
PDF
Building RESTful Applications
Nabeel Yoosuf
 
PPTX
Android and REST
Roman Woźniak
 
PPTX
Restful web services with java
Vinay Gopinath
 
PPTX
JAX-RS 2.0 and OData
Anil Allewar
 
Build Your First Java Jersey JAX-RS REST Web Service in less than 15 Minutes
Robert Li
 
Building Restful Web Services with Java
Vassil Popovski
 
Html servlet example
rvpprash
 
Developing RESTful WebServices using Jersey
b_kathir
 
Restful web services_tutorial
philip75020
 
Introduction to Restful Web Services
weili_at_slideshare
 
E-Services TP2 ISI by Ettaieb Abdessattar
Abdessattar Ettaieb
 
Introduction to RESTful Webservices in JAVA
psrpatnaik
 
RESTful Java With JAX RS 1st Edition Bill Burke
rohismhmob88
 
JavaEE and RESTful development - WSO2 Colombo Meetup
Sagara Gunathunga
 
RESTful Java With JAX RS 1st Edition Bill Burke
jolokmertah
 
RESTful web service with JBoss Fuse
ejlp12
 
JavaEE6 my way
Nicola Pedot
 
Rest overview briefing
◄ vaquar khan ► ★✔
 
Jersey
Yung-Lin Ho
 
RESTful application with JAX-RS and how to expose and test them
Kumaraswamy M
 
Building RESTful Applications
Nabeel Yoosuf
 
Android and REST
Roman Woźniak
 
Restful web services with java
Vinay Gopinath
 
JAX-RS 2.0 and OData
Anil Allewar
 
Ad

Recently uploaded (20)

PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 

Rest hello world_tutorial

  • 1. 1 Hello World RESTful web service tutorial Balázs Simon ([email protected]), BME IIT, 2015 1 Introduction This document describes how to create a Hello World RESTful web service in Eclipse using JAX-RS and WildFly. 2 RESTful service Create a new Dynamic Web Project in Eclipse called HelloRest. Make sure to select Generate web.xml deployment descriptor at the end of the wizard. The web project should look like this:
  • 2. 2 The JAX-RS annotated classes will be handled by a special servlet. This servlet must be declared in the web.xml file. Change the web.xml file so that it contains the following lines shown with yellow background: <?xml version="1.0" encoding="UTF-8"?> <web-app id="WebApp_ID" version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"> <display-name>HelloRest</display-name> <servlet-mapping> <servlet-name>javax.ws.rs.core.Application</servlet-name> <url-pattern>/rest/*</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> </web-app> Create a new interface called IHello and a class called Hello in the src folder under the package hellorest:
  • 3. 3 The IHello.java should contain the following code: package hellorest; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.QueryParam; @Path("hello") public interface IHello { @GET @Path("sayHello") public String sayHello(@QueryParam("name") String name); } The Hello.java should contain the following code: package hellorest; public class Hello implements IHello { @Override public String sayHello(String name) { return "Hello: "+name; } } Deploy the application to the server. It should be deployed without errors: To test the service, type the following URL into a browser (FireFox, Chrome, IE, etc.): http://localhost:8080/HelloRest/rest/hello/sayHello?name=me The response should be:
  • 4. 4 The URL has the following structure:  http://localhost:8080 – the protocol, domain name and port number of the server  /HelloRest – the name of the web application  /rest – the mapping of the REST servlet in the web.xml file  /hello – the @Path mapping of the IHello interface  /sayHello – the @Path mapping of the sayHello operation  ?name=me – the name and value passed as a @QueryParam 3 HTML client Create an HTML file called HelloClient.html under the WebContent folder: The contents of the file should be the following: <!DOCTYPE html> <html> <head> <meta charset="ISO-8859-1"> <title>Hello REST client</title> </head> <body> <form method="get" action="rest/hello/sayHello"> Type your name: <input type="text" name="name"/> <input type="submit" value="Say hello"/> </form> </body> </html>
  • 5. 5 Redeploy the application to the server, and open the following URL in a browser: http://localhost:8080/HelloRest/HelloClient.html This is where the HTML is accessible. The following page should be loaded in the browser: Type something in the text field and click the Say hello button: The result should be the following: 4 Java client using RESTeasy RESTeasy is the JAX-RS implementation of the WildFly server. It also has a client library, which can be used in console applications. This example will show how. RESTeasy requires some additional dependencies, so the easiest way to create a client is to use Maven. Create a new Maven Project in Eclipse called HelloRestClient:
  • 6. 6 Click Next, and select the Create a simple project check-box: Click Next and type HelloRestClient for both Group Id and Artifact Id:
  • 7. 7 Click Finish, and the project should look like this: Edit the pom.xml and add the following lines shown with yellow background: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>HelloRestClient</groupId> <artifactId>HelloRestClient</artifactId> <version>0.0.1-SNAPSHOT</version> <dependencies> <dependency> <groupId>org.jboss.resteasy</groupId> <artifactId>resteasy-client</artifactId> <version>3.0.10.Final</version> </dependency> </dependencies> </project> 4.1 Untyped client Create a new class called UntypedHelloClient under the package hellorestclient with the following content: package hellorestclient; import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.Response; public class UntypedHelloClient { public static void main(String[] args) { try{ // Create a new RESTeasy client through the JAX-RS API: Client client = ClientBuilder.newClient(); // The base URL of the service: WebTarget target = client.target("http://localhost:8080/HelloRest/rest");
  • 8. 8 // Building the relative URL manually for the sayHello method: WebTarget hello = target.path("hello").path("sayHello").queryParam("name", "me"); // Get the response from the target URL: Response response = hello.request().get(); // Read the result as a String: String result = response.readEntity(String.class); // Print the result to the standard output: System.out.println(result); // Close the connection: response.close(); } catch (Exception ex) { ex.printStackTrace(); } } } The project should look like this: Right click on the UntypedHelloClient.java and select Run As > Java Application. It should print the following:
  • 9. 9 4.2 Typed client Create an interface called IHello under the package hellorestclient with the following content: package hellorestclient; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.QueryParam; @Path("hello") public interface IHello { @GET @Path("sayHello") public String sayHello(@QueryParam("name") String name); } Create a class called TypedHelloClient under the package hellorestclient with the following content: package hellorestclient; import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; import javax.ws.rs.client.WebTarget; import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget; public class TypedHelloClient { public static void main(String[] args) { try { // Create a new RESTeasy client through the JAX-RS API: Client client = ClientBuilder.newClient(); // The base URL of the service: WebTarget target = client.target("http://localhost:8080/HelloRest/rest"); // Cast it to ResteasyWebTarget: ResteasyWebTarget rtarget = (ResteasyWebTarget)target; // Get a typed interface: IHello hello = rtarget.proxy(IHello.class); // Call the service as a normal Java object: String result = hello.sayHello("me"); // Print the result: System.out.println(result); } catch (Exception ex) { ex.printStackTrace(); } } } Right click on the TypedHelloClient.java and select Run As > Java Application. It should print the following: