I want to create a "mock" server using Ratpack.
First, I'm reading from a folder and defining a list of pairs, each pair has:
- A path
- The mock response for that path
I want to launch a server that defines those routes and responses:
// this is already done; returns smth such as:
def getServerRules() {
[ path: "/books", response: [...] ],
[ path: "/books/42", response: [ title: "this is a mock" ] ],
[ path: "/books/42/reviews", response: [ ... ] ],
...
]
def run() {
def rules = getServerRules()
ratpack {
handlers {
get( ??? rule.path ??? ) {
render json( ??? rule.response ??? )
}
}
}
}
Can I iterate over those rules
in order to define a handler for each item somehow?