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 * This method explained:
19 * <ul>
20 * <li>{@link GET}, it accepts HTTP GET requests</li>
21 * <li>{@link Produces Produces("text/plain")}, the HTTP response content type will be {@code text/plain}</li>
22 * <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
23 * {@link PathParam PathParam("name")}</li>
24 * </ul>
25 */
26 @GET
27 @Produces("text/plain")
28 @Path("{name}")
29 public String sayHelloTo(@PathParam("name") String name) {
30 return "Hello " + name;
31 }
32 }