Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Simple web server
- @GrabConfig(systemClassLoader=true)
- @Grapes([
- @Grab(group='io.ratpack', module='ratpack-core', version='1.9.0'),
- @Grab(group='io.ratpack', module='ratpack-groovy', version='1.9.0'),
- @GrabExclude('org.codehaus.groovy:groovy-all'),
- @Grab('org.slf4j:slf4j-simple:1.7.30')
- ])
- import org.eclipse.jetty.servlet.*
- import static ratpack.groovy.Groovy.ratpack
- import groovy.json.*
- ratpack {
- serverConfig {
- port(5056)
- }
- handlers {
- get {
- render "Hello World!"
- }
- get(":one") { ctx ->
- def result = [:]
- result['one'] = ctx.getPathTokens().get("one")
- render groovy.json.JsonOutput.toJson(result)
- }
- get(":one/:two") { ctx ->
- def result = [:]
- result['one'] = ctx.getPathTokens().get("one")
- result['two'] = ctx.getPathTokens().get("two")
- render groovy.json.JsonOutput.toJson(result)
- }
- get(":one/:two/:three") { ctx ->
- def result = [:]
- result['one'] = ctx.getPathTokens().get("one")
- result['two'] = ctx.getPathTokens().get("two")
- result['three'] = ctx.getPathTokens().get("three")
- render groovy.json.JsonOutput.toJson(result)
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement