Advertisement
OscarBesga_Panel

Simple web server

Jun 28th, 2022
2,523
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Groovy 1.32 KB | None | 0 0
  1. // Simple web server
  2. @GrabConfig(systemClassLoader=true)
  3. @Grapes([
  4.         @Grab(group='io.ratpack', module='ratpack-core', version='1.9.0'),
  5.         @Grab(group='io.ratpack', module='ratpack-groovy', version='1.9.0'),
  6.         @GrabExclude('org.codehaus.groovy:groovy-all'),
  7.         @Grab('org.slf4j:slf4j-simple:1.7.30')
  8. ])
  9.  
  10. import org.eclipse.jetty.servlet.*
  11. import static ratpack.groovy.Groovy.ratpack
  12. import groovy.json.*
  13.  
  14. ratpack {
  15.     serverConfig {
  16.         port(5056)
  17.     }
  18.     handlers {
  19.         get {
  20.             render "Hello World!"
  21.         }
  22.         get(":one") { ctx ->
  23.             def result = [:]
  24.             result['one'] = ctx.getPathTokens().get("one")
  25.             render  groovy.json.JsonOutput.toJson(result)
  26.         }
  27.         get(":one/:two") { ctx ->
  28.             def result = [:]
  29.             result['one'] = ctx.getPathTokens().get("one")
  30.             result['two'] = ctx.getPathTokens().get("two")
  31.             render  groovy.json.JsonOutput.toJson(result)
  32.         }
  33.         get(":one/:two/:three") { ctx ->
  34.             def result = [:]
  35.             result['one'] = ctx.getPathTokens().get("one")
  36.             result['two'] = ctx.getPathTokens().get("two")
  37.             result['three'] = ctx.getPathTokens().get("three")
  38.             render  groovy.json.JsonOutput.toJson(result)
  39.         }
  40.     }
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement