REST Web Services with Java Part 3 - vulabvulab

Posted on 06 March 2017 by Srinivas Nelakuditi

REST Web Services with Java Part 3

Let us look at a sample web service code snippet created using JAX-RS annotations

package com.vulab.code;


// The Java class will be hosted at the URI path "/helloworld"
public class HelloWorldResource {

     // The Java method will process HTTP GET requests
     public String helloWorldVulab() {
          return "Hello World Vulab";

In the above code snippet. @Path annotation is having the value of /helloworld

If a client wants to call the method helloWorldVulab, They can just use this URL in the web browser.

Because you are automatically making a HTTP GET request. You call above will match with the @PATH annotation value and as you are making a HTTP GET request, it matches with @GET annotation on method helloWorldVulab. The method executes and you can see ‘Hello World Vulab’ on the web browser. @Produces annotation will allow the method to send the text as plain text. You can even send JSON or XML back to the caller with the @Produces annotation.


Leave a Reply