Which method is used to send a POST request in RestAssured?
A) post()
B) get()
C) put()
D) delete()
Answer:
A) post()
Explanation:
The post()
method in RestAssured is used to send an HTTP POST request. This method is typically used when you want to submit data to be processed to a specified resource.
For example:
import static io.restassured.RestAssured.*;
given().
body("{\"key\":\"value\"}").
when().
post("/api/resource").
then().
statusCode(201);
In this example, the post()
method sends a POST request with a JSON body to the specified API endpoint and checks that the response status code is 201.