Use to defined end points responses. Groovy def router = server.router() .get("/hello/:name") { request -> server.response([message: "hello ${request.param("name")}"]) } .get("/bye/:name") { request -> server.response([message: "bye ${request.param("name")}"]) } Check servers/import-and-dependencies Import And Dependencies for prerequisites. Java WebTauRouter router = server.router() .get("/hello/:name", (request) -> server.response(map("message", "hello " + request.param("name")))) .get("/bye/:name", (request) -> server.response(map("message", "bye " + request.param("name")))); Check servers/import-and-dependencies Import And Dependencies for prerequisites.
Use and a router to create a server with controlled responses Groovy def myServer = server.fake("my-rest-server", router) http.get("${myServer.baseUrl}/hello/person") { message.should == "hello person" } http.get("${myServer.baseUrl}/bye/person") { message.should == "bye person" } Java myServer = server.fake("my-rest-server", router); http.get(myServer.getBaseUrl() + "/hello/person", ((header, body) -> { body.get("message").should(equal("hello person")); })); http.get(myServer.getBaseUrl() + "/bye/person?politeFactor=2", ((header, body) -> { body.get("message").should(equal("bye person")); })); Note: If you omit serverId parameter, an auto generated one will be used instead. It affects what you see in the generated report