A POST request is used to send data to the server, for example, customer information, file upload, etc. using HTML forms.
public class ReqRes
{
@BeforeClass
public void setup()
{
RestAssured.baseURI = "https://reqres.in/";
RestAssured.basePath = "api";
}
/*POST Request Example*/
@Test(enabled=true)
public void postRequestExam()
{
Response res =
given()
.header("Content-Type", "application/json")
.body("{\n" +
" \"name\": \"Tarun Goswami\",\n" +
" \"job\": \"QA\"\n" +
"}")
.when()
.post("/users")
.then()
.statusCode(201)
.extract().response();
System.out.println(res.body().prettyPrint());
}
}
Output
{
"name": "Tarun Goswami",
"job": "QA",
"id": "591",
"createdAt": "2020-07-24T07:38:08.739Z"
}
Tue, 09/01/2020 - 22:50
Tarun Goswami is a highly experienced professional, currently serving as Technical Lead at a well-established IT services company. With over 12 years of experience across multiple domains, he demonstrates his expertise and passion for the industry through his engaging and informative blog writing in his spare time.
Comments