To send a POST request with a JSON payload :
import static io.restassured.RestAssured.*;
import static org.hamcrest.Matchers.*;
public class PostRequestExample {
public static void main(String[] args) {
given()
.header("Content-Type", "application/json") // Set Content-Type
.body("{ \"title\": \"foo\", \"body\": \"bar\", \"userId\": 1 }") // Set request body
.when()
.post("https://jsonplaceholder.typicode.com/posts") // Send POST request
.then()
.statusCode(201) // Verify the status code is 201 (Created)
.body("id", notNullValue()); // Verify the response contains an 'id'
}
}?