Created
April 2, 2015 15:39
-
-
Save davidmc24/6b732f0e037dc50f9a84 to your computer and use it in GitHub Desktop.
Quick demo of ratpack prefix handling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@GrabResolver(name="OJO", root="https://oss.jfrog.org/artifactory/repo") | |
@Grab("io.ratpack:ratpack-groovy:0.9.15") | |
import static ratpack.groovy.Groovy.ratpack | |
import static ratpack.groovy.Groovy.groovyMarkupTemplate | |
import ratpack.groovy.template.MarkupTemplateModule | |
import ratpack.handling.* | |
@Grab("org.slf4j:slf4j-simple:1.7.12") | |
import org.slf4j.Logger | |
// You can change anything in the ratpack {} closure without needing to restart | |
class MyHandler implements Handler { | |
void handle(Context context) throws Exception { | |
println "Got request for ${context.request.path}" | |
context.response.send("Hello World!") | |
} | |
} | |
ratpack { | |
bindings { | |
add new MarkupTemplateModule() | |
} | |
handlers { | |
get { | |
response.send "This is the app root (also try: /date and /some.txt)" | |
} | |
get("date") { | |
render groovyMarkupTemplate("date.gtpl") | |
} | |
prefix("myassets") { | |
handler(new MyHandler()) | |
} | |
assets "public" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment