http.get|post|put|delete methods have overloads to let you supply additional data in addition to URL:Query parameters Request header Payload (where applicable) Validation block Overloads maintain relative order, but you can omit any additional data.Here is http.get quick example: Groovy http.get("/query", http.header([h1: "v1"])) { price.should == 100 } Check HTTP/import-and-dependencies Import And Dependencies for prerequisites. Java http.get("/query", http.header("h1", "v1"), ((header, body) -> { body.get("price").should(equal(100)); })); Check HTTP/import-and-dependencies Import And Dependencies for prerequisites.
Implicit statusCode Check
By default, WebTau automatically assert statusCode based on method. Method Implicitly Expected Code [{text=GET, type=SimpleText}] [{text=200, type=SimpleText}] [{text=POST, type=SimpleText}] [{text=201, type=SimpleText}] [{text=PUT, type=SimpleText}] [{text=200, type=SimpleText}] [{text=PUT (no response), type=SimpleText}] [{text=204, type=SimpleText}] [{text=DELETE, type=SimpleText}] [{text=200, type=SimpleText}] [{text=DELETE (no response), type=SimpleText}] [{text=204, type=SimpleText}] To turn it off, provide an explicit statusCode assertion. Groovy http.post("/resource") { statusCode.should == 200 // explicit check that override default 201 (for POST) implicit check } Java http.post("/resource", (header, body) -> { header.statusCode.should(equal(200)); // explicit check that override default 201 (for POST) implicit check });
java http.get(url, [queryParams], [header], [validationBlock]) url String getting-started/configuration#config-file relative or absolute URL to send GET request to queryParams HttpQueryParams | Map HTTP/query-parameters query parameters to attach to URL header HttpHeader HTTP/header request header to send validationBlock HttpResponseValidator validation block of code to HTTP/matchers assert and access response body and header Groovy def id = http.get("/query", [q1: "v1"], http.header([h1: "v1"])) { price.should == 100 // validation return id // optional return } http.get("/query", [q1: "v1"]) { price.should == 100 } http.get("/query", http.header([h1: "v1"])) { price.should == 100 } http.get("/query") { price.should == 100 } http.get("/query") Java String id = http.get("/query", http.query("q1", "v1"), http.header("h1", "v1"), ((header, body) -> { body.get("price").should(equal(100)); // validation return body.get("id"); // optional return })); http.get("/query", http.query("q1", "v1"), ((header, body) -> { body.get("price").should(equal(100)); })); http.get("/query", http.header("h1", "v1"), ((header, body) -> { body.get("price").should(equal(100)); })); http.get("/query", ((header, body) -> { body.get("price").should(equal(100)); })); http.get("/query");
java http.post(url, [queryParams], [header], [body], [validationBlock]) url String getting-started/configuration#config-file relative or absolute URL to send GET request to queryParams HttpQueryParams | Map HTTP/query-parameters query parameters to attach to URL header HttpHeader HTTP/header request header to send body HttpRequestBody | Map | List HTTP/body request body to send with a request validationBlock HttpResponseValidator validation block of code to HTTP/matchers assert and access response body and header Groovy def id = http.post("/chat", http.query([q1: "v1"]), http.header([h1: "v1"]), [message: "hello"]) { status.should == "SUCCESS" // validation return id // optional return } http.post("/chat", http.query([q1: "v1"]), [message: "hello"]) { status.should == "SUCCESS" } http.post("/chat", http.header([h1: "v1"]), [message: "hello"]) { status.should == "SUCCESS" } http.post("/chat", [message: "hello", priority: "HIGH"]) { status.should == "SUCCESS" } http.post("/chat") { status.should == "SUCCESS" } http.post("/chat") Java String id = http.post("/chat", http.query("q1", "v1"), http.header("h1", "v1"), http.json("message", "hello"), (header, body) -> { body.get("status").should(equal("SUCCESS")); // validation return body.get("id"); // optional return }); http.post("/chat", http.query("q1", "v1"), http.json("message", "hello"), (header, body) -> { body.get("status").should(equal("SUCCESS")); }); http.post("/chat", http.header("h1", "v1"), http.json("message", "hello"), (header, body) -> { body.get("status").should(equal("SUCCESS")); }); http.post("/chat", http.json("message", "hello", "priority", "high"), (header, body) -> { body.get("status").should(equal("SUCCESS")); }); http.post("/chat", (header, body) -> { body.get("status").should(equal("SUCCESS")); }); http.post("/chat");
java http.put(url, [queryParams], [header], [body], [validationBlock]) url String getting-started/configuration#config-file relative or absolute URL to send GET request to queryParams HttpQueryParams | Map HTTP/query-parameters query parameters to attach to URL header HttpHeader HTTP/header request header to send body HttpRequestBody | Map | List HTTP/body request body to send with a request validationBlock HttpResponseValidator validation block of code to HTTP/matchers assert and access response body and header Groovy def id = http.put("/chat/id1", http.query([q1: "v1"]), http.header([h1: "v1"]), [message: "hello"]) { status.should == "SUCCESS" // validation return id // optional return } http.put("/chat/id1", http.query([q1: "v1"]), [message: "hello"]) { status.should == "SUCCESS" } http.put("/chat/id1", http.header([h1: "v1"]), [message: "hello"]) { status.should == "SUCCESS" } http.put("/chat/id1", [message: "hello"]) { status.should == "SUCCESS" } http.put("/chat/id1") { status.should == "SUCCESS" } http.put("/chat/id1") Java String id = http.put("/chat/id1", http.query("q1", "v1"), http.header("h1", "v1"), http.json("message", "hello"), (header, body) -> { body.get("status").should(equal("SUCCESS")); // validation return body.get("id"); // optional return }); http.put("/chat/id1", http.query("q1", "v1"), http.json("message", "hello"), (header, body) -> { body.get("status").should(equal("SUCCESS")); }); http.put("/chat/id1", http.header("h1", "v1"), http.json("message", "hello"), (header, body) -> { body.get("status").should(equal("SUCCESS")); }); http.put("/chat/id1", http.json("message", "hello"), (header, body) -> { body.get("status").should(equal("SUCCESS")); }); http.put("/chat/id1", (header, body) -> { body.get("status").should(equal("SUCCESS")); }); http.put("/chat/id1");
java http.delete(url, [queryParams], [header], [validationBlock]) url String getting-started/configuration#config-file relative or absolute URL to send GET request to queryParams HttpQueryParams | Map HTTP/query-parameters query parameters to attach to URL header HttpHeader HTTP/header request header to send validationBlock HttpResponseValidator validation block of code to HTTP/matchers assert and access response body and header Groovy def id = http.delete("/chat/id1", [q1: "v1"], http.header([h1: "v1"])) { status.should == "SUCCESS" // validation return id // optional return } http.delete("/chat/id1", [q1: "v1"]) { status.should == "SUCCESS" } http.delete("/chat/id1", http.header([h1: "v1"])) { status.should == "SUCCESS" } http.delete("/chat/id1") { status.should == "SUCCESS" } http.delete("/chat/id1") Java String id = http.delete("/chat/id1", http.query("q1", "v1"), http.header("h1", "v1"), ((header, body) -> { body.get("status").should(equal("SUCCESS")); // validation return body.get("id"); // optional return })); http.delete("/chat/id1", http.query("q1", "v1"), ((header, body) -> { body.get("status").should(equal("SUCCESS")); })); http.delete("/chat/id1", http.header("h1", "v1"), ((header, body) -> { body.get("status").should(equal("SUCCESS")); })); http.delete("/chat/id1", ((header, body) -> { body.get("status").should(equal("SUCCESS")); })); http.delete("/chat/id1");
java http.patch(url, [queryParams], [header], [body], [validationBlock]) url String getting-started/configuration#config-file relative or absolute URL to send GET request to queryParams HttpQueryParams | Map HTTP/query-parameters query parameters to attach to URL header HttpHeader HTTP/header request header to send body HttpRequestBody | Map | List HTTP/body request body to send with a request validationBlock HttpResponseValidator validation block of code to HTTP/matchers assert and access response body and header Groovy def id = http.patch("/chat/id1", http.query([q1: "v1"]), http.header([h1: "v1"]), [message: "hello"]) { status.should == "SUCCESS" // validation return id // optional return } http.patch("/chat/id1", http.query([q1: "v1"]), [message: "hello"]) { status.should == "SUCCESS" } http.patch("/chat/id1", http.header([h1: "v1"]), [message: "hello"]) { status.should == "SUCCESS" } http.patch("/chat/id1", [message: "hello"]) { status.should == "SUCCESS" } http.patch("/chat/id1") { status.should == "SUCCESS" } http.patch("/chat/id1") Java String id = http.patch("/chat/id1", http.query("q1", "v1"), http.header("h1", "v1"), http.json("message", "hello"), (header, body) -> { body.get("status").should(equal("SUCCESS")); // validation return body.get("id"); // optional return }); http.patch("/chat/id1", http.query("q1", "v1"), http.json("message", "hello"), (header, body) -> { body.get("status").should(equal("SUCCESS")); }); http.patch("/chat/id1", http.header("h1", "v1"), http.json("message", "hello"), (header, body) -> { body.get("status").should(equal("SUCCESS")); }); http.patch("/chat/id1", http.json("message", "hello"), (header, body) -> { body.get("status").should(equal("SUCCESS")); }); http.patch("/chat/id1", (header, body) -> { body.get("status").should(equal("SUCCESS")); }); http.patch("/chat/id1");
Use ping to check if an end point responds 200 to GET method Groovy if (!http.ping("/end-point")) { http.post("/cluster-master", [restart: "server-one"]) } Java if (!http.ping("/end-point")) { http.post("/cluster-master", http.json("restart", "server-one")); } java boolean http.ping(url, [queryParams], [header]) url String getting-started/configuration#config-file relative or absolute URL to send GET request to queryParams HttpQueryParams | Map HTTP/query-parameters query parameters to attach to URL header HttpHeader HTTP/header request header to send Groovy http.ping("/end-point", [queryParam1: "queryParamValue1"], http.header(["X-flag": "test"])) http.ping("/end-point", [queryParam1: "queryParamValue1"]) http.ping("/end-point", http.header(["X-flag": "test"])) http.ping("/end-point") Java http.ping("/end-point", http.query("queryParam1", "queryParamValue1"), http.header("X-flag", "test")); http.ping("/end-point", http.query("queryParam1", "queryParamValue1")); http.ping("/end-point", http.header("X-flag", "test")); http.ping("/end-point");