All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.google.sitebricks.example.RestfulWebServiceWithSubpaths Maven / Gradle / Ivy

The newest version!
package com.google.sitebricks.example;

import com.google.inject.name.Named;
import com.google.sitebricks.At;
import com.google.sitebricks.headless.Reply;
import com.google.sitebricks.headless.Service;
import com.google.sitebricks.http.Get;
import com.google.sitebricks.http.Post;

/**
 * Demonstrates subpaths in a restful webservice.
 *
 * @author Dhanji R. Prasanna (dhanji@gmail com)
 */
@At("/superpath") @Service
public class RestfulWebServiceWithSubpaths {
  public static final String TOPLEVEL = "toplevel";
  public static final String PATH_1 = "path1";
  public static final String PATH_2 = "path2";
  public static final String PATH_3 = "path3";

  @Get
  public Reply topLevel() {
    return Reply.with(TOPLEVEL);
  }

  @At("/subpath1") @Post
  public Reply path1() {
    return Reply.with(PATH_1);
  }

  @At("/subpath2") @Post
  public Reply path2() {
    return Reply.with(PATH_2);
  }

  @At("/subpath3") @Post
  public Reply path3() {
    return Reply.with(PATH_3);
  }

  @At("/subpath1/:variable") @Post
  public Reply variable(@Named("variable") String arg) {
    return Reply.with(arg);
  }

  @At("/subpath1/:variable/:id") @Post
  public Reply variableSecondLevel(@Named("variable") String arg, @Named("id") String id) {
    return Reply.with(arg + "_" + id);
  }

  @At("/subpath3/:sec") @Post
  public Reply variableSubpath2(@Named("sec") String arg) {
    return Reply.with(arg);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy