1 package com.atlassian.plugins.rest.sample.helloworld;
2
3 import com.atlassian.plugins.rest.common.security.AnonymousAllowed;
4
5 import javax.ws.rs.GET;
6 import javax.ws.rs.Path;
7 import javax.ws.rs.PathParam;
8 import javax.ws.rs.Produces;
9
10 /*
11 * This resource serves paths that start with /hello as per the {@link Path Path("/hello")} annotation. The {@link AnonymousAllowed} ensures the resource is accessible for user who have not
12 * authenticated.
13 */
14 @Path("/hello")
15 @AnonymousAllowed
16 public class HelloWorld
17 {
18 /*
19 * This method explained:
20 * <ul>
21 * <li>{@link GET}, it accepts HTTP GET requests</li>
22 * <li>{@link Produces Produces("text/plain")}, the HTTP response content type will be {@code text/plain}</li>
23 * <li>{@link Path Path("{name}")}, this method will serve path like /hello/<name> where name can be any valid path element. It will be then passed as a parameter to the parameter annotated with
24 * {@link PathParam PathParam("name")}</li>
25 * </ul>
26 */
27 @GET
28 @Produces("text/plain")
29 @Path("{name}")
30 public String sayHelloTo(@PathParam("name") String name)
31 {
32 return "Hello " + name;
33 }
34 }