this is the simple example of getting the hello world plain text message as output on calling the GET request.
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path("/hello")
public class HelloExample {
@GET
@Produces(MediaType.APPLICATION_TEXT)
public String getUsers(){
return "Hello World";
}
}
you also nedd to add the following in the web.xml file to completely setup the api.
<display-name>User Message</display-name>
<servlet>
<servlet-name>Jersey REST Api</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servletclass>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>your_package_name</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Api</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
After that you will have to deploy this on your server and then open the following Url in your browser to get the output. your_server_name/your_appl_name/rest/hello.