Created
July 28, 2014 08:49
-
-
Save beckje01/136fce42cdba7036a988 to your computer and use it in GitHub Desktop.
Ratpack Context Examples
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:0.9.6') | |
import ratpack.registry.RegistrySpec | |
import static ratpack.groovy.Groovy.* | |
import static ratpack.registry.Registries.registry | |
ratpack { | |
handlers { | |
handler { | |
request.register(Person.class, new Person(name: "Test")) | |
next() | |
} | |
handler { | |
next(registry({ RegistrySpec registrySpec -> | |
registrySpec.add(Foo.class, new Foo(value: "fooValue")) | |
def people = [] | |
people.add(new Person(name: "PersonList1")) | |
people.add(new Person(name: "PersonList2")) | |
registrySpec.add(PersonList, people) | |
})) | |
} | |
get { Person p -> | |
def people = maybeGet(PersonList.class) | |
render "Hello ${p.name}, ${people?.size()}" | |
} | |
} | |
} | |
class Person { | |
String name | |
} | |
class PersonList extends ArrayList<Person> { | |
} | |
class Foo { | |
String value | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment