Last active
November 4, 2020 14:42
-
-
Save fmamud/20607540ed5cb3a4b783714a4f427539 to your computer and use it in GitHub Desktop.
Ratpack simple example that serves first json file found in current directory
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
@Grab('io.ratpack:ratpack-groovy:1.8.0') | |
import static ratpack.groovy.Groovy.ratpack | |
import static ratpack.jackson.Jackson.json | |
import groovy.json.JsonSlurper | |
def parser = new JsonSlurper() | |
ratpack { | |
handlers { | |
get { | |
def file = new File('.').listFiles().find { it.name.endsWith('.json') } | |
def text = file ? file.text : '{}' | |
render json(parser.parseText(text)) | |
} | |
post("event-types") { | |
parse(jsonNode()) | |
.then { n -> | |
println(n.toString()) | |
render n.toString() | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment