1 2 3 4 5 6 7 8 9 | RatpackServer.start(server -> server .handlers(chain -> chain.post("form", ctx -> ctx.parse(Form.class) .then(form -> ctx.render(form.get("name"))) ).post("file", ctx -> ctx.parse(Form.class).then(form -> ctx.render(form.file("file").getText())) ) ) ); |
1 2 3 4 5 6 7 8 9 | RatpackServer.start(server -> server.handlers(chain -> chain.post(ctx -> { ctx.parse(fromJson(User.class)) .map(user -> new User(user.getId(), user.getName().toUpperCase())) .then(user -> ctx.render(json(user))); }) ) ); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | public class StaticFiles { public static void main(String[] args) throws Exception { Path baseDir = Paths.get("app").toAbsolutePath(); new StaticFiles().start(baseDir); } public void start(final Path baseDir) throws Exception { RatpackServer.start(server -> server .serverConfig(c -> c.baseDir(baseDir)) .handlers(chain -> chain .files(f -> f.dir("public").indexFiles("index.html")) ) ); } } |
1 2 3 4 5 6 7 8 9 | RatpackServer.start(server -> server.handlers(chain -> chain.get(ctx -> { String userId = ctx.getRequest().getHeaders().get("X-UID"); ctx.getResponse().getHeaders().set("X-Poweredby", "Ratpack"); ctx.render(userId); }) ) ); |
1 2 3 4 5 6 7 8 9 | RatpackServer.start(server -> server.handlers(chain -> chain.get(ctx -> { String userId = ctx.getRequest().oneCookie("userId"); ctx.getResponse().cookie("userId", "value"); ctx.render(userId); }) ) ); |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |