The
@Path
annotation's value is a relative URI path. This is a very simple use of the @Path
annotation. The following code example provides a simple example of a root-resource class using the JAX-RS annotations:
@Path("helloWorld") public class HelloWorldResource { @GET @Produces("text/plain") public String sayHello() { return "Hello World!"; } }
In the preceding example, the Java class will be hosted at the URI path /helloworld
. What makes JAX-RS so useful is that one can embed variables in the URIs.
URI path templates are URIs with variables that are embedded within the URI syntax. These variables are substituted during runtime so that a resource can respond to a request, based on the substituted URI. The variables are denoted by curly braces shown as follows:
Class-level:
@Path("/helloWorld/{name}") public class HelloWorldResource { @GET @Produces("text/plain") public String sayHello(@PathParam("name") String name) { return "Hello, " +...